Forum Moderators: coopster

Message Too Old, No Replies

php restore session problem

         

StickeR

1:33 am on Aug 10, 2010 (gmt 0)

10+ Year Member



I am having an anooying issue when trying to restore a session.

I am using the Javascript Uploadify / swfupload file upload solution, which kills the session during the upload. (this appears common for swfupload)

Everywhere on the web I am reading the solution is to send the current sessionid along with the form to the upload script, and then there restore the session by settings its ID again, sounds solid enough in theory.

The current code is along the line of the code shown below, in this case the current document is the same as where the file is submitted to (upload.php), Ive also tried to post to another page, no luck there either.
<?php
error_reporting(-1);
$formposted=false;
if(isset($_POST['session_name'])){ //is set, test have proven so
$formposted = true;
session_id($_POST['session_name']);
}
session_start();
if(!$formposted){
$_SESSION['sessionvar'] = 'hello world';
}else{
echo $_SESSION['sessionvar']; //always empty
}

?>


<script type="text/javascript">
$(document).ready(function() {
$("#uploadify").uploadify({
'uploader' : '/uploadify/uploadify.swf',
'script' : '/upload.php',
'cancelImg' : 'uploadify/cancel.png',
'folder' : 'uploads',
'queueID' : 'fileQueue',
'scriptData': {'session_name': '<?php echo session_id(); ?>'},
'auto' : true,
'multi' : true
});
});
</script>


I'd sincerely appreciate it if anyone can assist me in clearing up this problem, as I'm getting slightly insane over this.

Many thanks in advance.
Regards,
Eelco

Matthew1980

7:26 am on Aug 10, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi there StickeR,

I admit, I'm a little confused here ;) Check that the $_SESSION is actually set in the $_COOKIE log in your browser, as PHPSESSID, because sessions are stored as cookie's in that PHPSESSID value that appears in the log.

Also, the session_start(); function should be placed at the very top of the php file, prefereably under the opening tag, followed by the error_reporting(E_ALL); function. This is done so that it is the first instruction that the compiler/parser reads - so in your example, setting the $_SESSION['sessionvar'] = "hello world"; wouldn't yield results (at least that's what happens for me)

I've never used uploadify so cannot comment on that.. I'm just commenting on the code that you have submitted.

Hope that makes sense,

Cheers,
MRb

StickeR

11:45 am on Aug 10, 2010 (gmt 0)

10+ Year Member



Thanks for the response, the code I pasted is incorrect anyway I just noticed, I copied and pasted several seperate parts. I will check your suggestion alter when i get home