manixrock Posted October 23, 2007 Share Posted October 23, 2007 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? Quote Link to comment https://forums.phpfreaks.com/topic/74491-how-do-i-get-session-variables-in-php-if-i-have-the-sid-but-_session-is-empty/ Share on other sites More sharing options...
otuatail Posted October 23, 2007 Share Posted October 23, 2007 If the variable does not exsist you will receive a null string As if($_SESSION['myvar'] == "") echo "Session does not exsist or is set to nothing"; Quote Link to comment https://forums.phpfreaks.com/topic/74491-how-do-i-get-session-variables-in-php-if-i-have-the-sid-but-_session-is-empty/#findComment-376444 Share on other sites More sharing options...
manixrock Posted October 23, 2007 Author Share Posted October 23, 2007 @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? Quote Link to comment https://forums.phpfreaks.com/topic/74491-how-do-i-get-session-variables-in-php-if-i-have-the-sid-but-_session-is-empty/#findComment-376478 Share on other sites More sharing options...
atlanta Posted October 23, 2007 Share Posted October 23, 2007 try using the session_id() ; in php it should send you the current session id . im still not sure if im understanding you.. refrence: http://us2.php.net/manual/en/function.session-id.php Quote Link to comment https://forums.phpfreaks.com/topic/74491-how-do-i-get-session-variables-in-php-if-i-have-the-sid-but-_session-is-empty/#findComment-376489 Share on other sites More sharing options...
manixrock Posted October 23, 2007 Author Share Posted October 23, 2007 Thanks for the help, but what i need is a bit more advanced that a missunderstanding of PHP. 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) ? Quote Link to comment https://forums.phpfreaks.com/topic/74491-how-do-i-get-session-variables-in-php-if-i-have-the-sid-but-_session-is-empty/#findComment-376506 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.