note 57875 deleted from function.session-start by peehaa
| From: | peehaa@php.net | Date: | Fri, 09 Dec 2016 22:01:33 +0000 |
| Subject: | note 57875 deleted from function.session-start by peehaa | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-208315@lists.php.net to get a copy of this message | ||
Note Submitter: jeremygiberson at gmail dot com
----
foltscane at yahoo dot com wrote about people losing session information on page redirects.
The problem is some times the redirect may kick you off to the next page before all the session
variables have been saved. The true solution to lost session vars on redirect is to simply call
session_write_close(); before setting the redirect header. This will insure that php finishes
writing the session info before page redirect gets underway.
ie:
<?
session_start();
$_SESSION['forward'] = "This session data will not be lost!";
session_write_close();
header('Location: nextpage.php');
?>