Hi everyone,
I am experiencing the infamous cookie bug and it's driving me mad. I searched the forums already and tried the following:
In an external jquery.gallery.js I have the initialization code for SWFU:
<?php
session_start();
?>
var swfu;
$(document).ready(function() {
[...]
swfu = new SWFUpload({
[...]
post_params: {"PHPSESSID" : "<?php echo session_id(); ?>"},
etc....
As you can see I initiated the session in this .js file aswell to get the current session ID for the post_params.
When browsing through the SourceCode Firefox recieves, the session id is resolved correctly and passed to the post_params.
In my swfupload.php I have the following workaround code on top
if (isset($_POST["PHPSESSID"])) {
session_id($_POST["PHPSESSID"]);
} else if (isset($_GET["PHPSESSID"])) {
session_id($_GET["PHPSESSID"]);
}
session_start();
echo session_id();
The JS alert, which shows the output of swfupload.php, also prints the correct session id.
If I understand the forum posts correctly, this is all I have to do to make it work, though there was some mentioning of "next, you have to restore the session data". I am not sure if this statement refers to my session_id() / session_start() in the swfupload.php, or if I have to somehow restore the data in my framework aswell. Since I developed the scripts myself I can tamper with the code in whatevery way I have to. I just need a hint which step I am missing to fully restore the session data.
(Btw, this also happens if I am just browsing to the site with the swfupload button, don't even have to upload something.)
October 15, 2009 - 9:25am
The code you show should manually restore a PHP session. Some frameworks handle the session themselves so if you are using something like CakePHP or another application framework you'll have to work around that.
But in standard PHP what you've done above is what we have done in the Demos and it seems to work for us.
May 16, 2010 - 10:44am
Can't restore session by posting and reading PHPSESSID (OT: consider using session_name()) if session.use_only_cookies is set to true.
Has anyone else seen this problem and/or have a solution?
May 17, 2010 - 10:42am
Can't you call session_id($newSessionID) before calling session_start() to work around this?
This is what we do, but we aren't using session_use_only_cookies.