Jump to content

How do I get session variables in PHP if I have the SID but $_SESSION is empty?


manixrock

Recommended Posts

I'm running a PHP chat server that accepts incoming connections that are made trough flash. This is running a flash chat on the user side. What I want to do is, if a user has already logged in on my site, to not ask the user to login again in the chat application, but rather to have the flash send the SESSIONID and auto-login the user. (the flash gets the SESSIONID by communicating with javascript which gets it trough "document.cookie"). So I need to get the session variables that are associated with that SESSIONID. Like $_SESSION['myvar'], which obviously it doesn't work.

 

One solution would be to make a GET request to some php on my site with the header "Cookie: [SESSIONID here]" like getsessionvars.php which would contain:

<?

session_start();

print_r($_SESSION);

?>

but I think there might be better ways.

 

Any ideeas?  8)

Link to comment
Share on other sites

@otuatail

Thanks for the reply.. but  ::)

 

Ofcourse the variables do NOT lie within the $_SESSION variable, since I'm not making a HTTP request. The php page is run with the command prompt, opens a socket and enters into an infinite loop waiting for connections. So there is no $_SESSION ofcourse. When the user enters a page on my site, a flash will apear that will connect trough a socket to the php server running on my server. It will send the SESSIONID as a simple message, NOT as a Cookie header. So I have to get SESSION variables from PHP having only the SESSIONID. Any ideeas?

Link to comment
Share on other sites

Thanks for the help, but what i need is a bit more advanced that a missunderstanding of PHP.  :P

 

To simplify this is what I need:

 

I have a user that has just logged in into my site. When he logs in the $_SESSION is filled with the username. $_SESSION['username'] = $username; Now everytime the user accesses a page on my server he sends the header "Cookie: SESSIONID" which is used by PHP to identify the $_SESSION variables.

 

Now the same user goes to a page on my site that contains a FLASH in it. On the user side, the flash communicates with javascript to get the "document.cookie", and then connects to my server (php script running in a continual loop waiting for an incoming socket connection) trough a socket (with XMLSocket). It first automatically sends the "<policy-file-request/>" message, which I respond to correctly, and the connection is established. Next the flash sends the message "SID=SESSIONID" to which the php should return the username associated with that SESSIONID.

 

How do I get the username from PHP knowing only the SESSIONID (and $_SESSION is obviously empty) ?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.