PHP session id and token issue

Official OpenTok Server-Side libraries

PHP session id and token issue

Postby Henrick » Wed Dec 14, 2011 10:15 am

Hi, I'm using the php version. I'm just beginning but I am having problems getting more than one person into a stream.

I assume my problem is that each time the web page loads it creates a different session id and token.

I have this at the start of my basictutorial.php file

Code: Select all
require_once 'opentok-php-sdk/API_Config.php';
        require_once 'opentok-php-sdk/OpenTokSDK.php';

        $apiObj = new OpenTokSDK(API_Config::API_KEY, API_Config::API_SECRET);

        $session = $apiObj->create_session($_SERVER["REMOTE_ADDR"]);

      $phpSessionVar = $session->getSessionId();
        $phpTokenVar = $apiObj->generate_token();

//just echoing vars to see if they are different each time the page is loaded
      echo $phpSessionVar;
      echo '<br />';
      echo '<br />';
      echo $phpTokenVar;



Then the web page is just the basic tutorial with the production server js linked in the head and the following:

Code: Select all
var sessionId = '<?=$phpSessionVar ?>'; // Replace with your session ID.
   var token = '<?=$phpTokenVar ?>'; // Should not be hard-coded.


Can anyone tell me where I am going wrong? When I navigate to createSession.php (sample file in the php download). It displays a token and session id. And when I print the session id and token out to the screen from the basic tutorial page it displays them. But they are different every time I open the page on a different computer and the only cam showing is the one that pc.

Can anyone point me in the right direction? Thanks
Was this post helpful? (0)
Henrick
 
Posts: 2
Joined: Wed Dec 14, 2011 9:56 am
Thumbs Up: 0

Re: PHP session id and token issue

Postby mumm » Wed Dec 14, 2011 11:08 am

Hi Henrick,

THe problem is that each user is connecting to a unique session. You need to give people the same session id that you want to be in a chat together. Generally, this is done by using a database to store the session id, and then giving it to the users that go to a specific path. However, each user should have their own unique token.

Jon
Was this post helpful? (0)
mumm
 
Posts: 392
Joined: Wed May 18, 2011 12:10 am
Thumbs Up: 28

Re: PHP session id and token issue

Postby Henrick » Wed Dec 14, 2011 11:17 am

Thanks for the reply Mumm.

The app is only ever going to be one to one and on one end is always going to the same. Would it be acceptable to hard code in the session_id and pass in the unique token each time instead of using a db?
Was this post helpful? (0)
Henrick
 
Posts: 2
Joined: Wed Dec 14, 2011 9:56 am
Thumbs Up: 0

Re: PHP session id and token issue

Postby mumm » Wed Dec 14, 2011 11:23 am

If you will only need one unique room, then yes it is fine to hard code the session id.
Was this post helpful? (0)
mumm
 
Posts: 392
Joined: Wed May 18, 2011 12:10 am
Thumbs Up: 28

Re: PHP session id and token issue

Postby hullfc » Fri Jan 25, 2013 6:17 am

Hi,

I'm interested in this approach.

When you say hard code, presumably I can't just make this up?

Can I just hard code in my session ID using a made-up number (123456), and then use the server side scripts to generate my session token?

Many thanks,

John
Was this post helpful? (0)
hullfc
 
Posts: 3
Joined: Thu Jan 24, 2013 4:26 pm
Thumbs Up: 0

Re: PHP session id and token issue

Postby jtsai » Fri Jan 25, 2013 1:58 pm

Yes you can hard code in your session id and generate tokens with server-side scripts.

John
Was this post helpful? (0)
Very helpful resource: Devs Checklist
Examples with OpenTok: Examples
User avatar
jtsai
 
Posts: 1954
Joined: Wed Sep 14, 2011 3:00 pm
Thumbs Up: 157

Re: PHP session id and token issue

Postby hullfc » Mon Jan 28, 2013 2:32 am

Perfect! Thanks very much for the reply.

John
Was this post helpful? (0)
hullfc
 
Posts: 3
Joined: Thu Jan 24, 2013 4:26 pm
Thumbs Up: 0

Re: PHP session id and token issue

Postby hullfc » Tue Jan 29, 2013 8:01 am

Hi,

I've tried this... I can generate new sessions and tokens, but when I want to hard code in a session ID, so that I can share it with others, I just get an error abut having an invalid session ID?
Was this post helpful? (0)
hullfc
 
Posts: 3
Joined: Thu Jan 24, 2013 4:26 pm
Thumbs Up: 0

Re: PHP session id and token issue

Postby jtsai » Tue Jan 29, 2013 2:47 pm

Can you give me the session id and token you are using?

John
Was this post helpful? (0)
Very helpful resource: Devs Checklist
Examples with OpenTok: Examples
User avatar
jtsai
 
Posts: 1954
Joined: Wed Sep 14, 2011 3:00 pm
Thumbs Up: 157


Return to Supported Server API (PHP, Java, Ruby, Python)



Who is online

Users browsing this forum: No registered users and 1 guest

cron