Saturday, February 21, 2009

PHP PHPSESSID=session_id() or $_GET['PHPSESSID'] not working ?

for my most recent project i was trying to use the YUI uploader to upload multiple files to the server. As the user is authenticated to get to the page the Session needs to be persisted.
But YUI Loader does not use cookies so that means the request that the YUI loader makes will have a new session.
To resolve this I sent the session ID as http://thewebsite.com/theuri?PHPSESSID=

well this doesn't work either. This seems to be because $_COOKIE variables take precedence over $_GET variables in the global scope or maybe $_GET['PHPSESSID'] is not supported at all now. So this is what i needed to do:

if ($_GET['PHPSESSID']) {
$_COOKIE['PHPSESSID'] = $_GET['PHPSESSID'];
}
The above code should be added anywhere before you use session_start() function. It would be ok to include it in the start of the script.

No comments: