Can I restore a PHP SESSION by its ID?

waterschaats picture waterschaats · Mar 18, 2011 · Viewed 7.7k times · Source

Im uploading files with the uploadify plugin. the PHP SESSION is lost during upload, is there a way to restore the session? Perhaps by its id?

Answer

Alec Gorge picture Alec Gorge · Mar 18, 2011

Yes. You need to add an option to uploadify:

$('#upload').uploadify({
    'scriptData':{'session_name':"<?php echo session_id(); ?>"}
});

And you need to add this to your PHP:

<?php
session_id($_POST['session_name']);
session_start();
?>

Then everything will be as expected.