note 64462 deleted from function.session-write-close by bjori
| From: | bjori@php.net | Date: | Fri, 14 Apr 2006 22:19:26 +0000 |
| Subject: | note 64462 deleted from function.session-write-close by bjori | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-108118@lists.php.net to get a copy of this message | ||
Note Submitter: junk at vhd dot com dot au
Reason: bad code
----
I had a problem where some session variables were not carrying over to the other page.
The post by "risaac at deadletter dot com" gave me a clue. The session management does not
have enough time to write the changes to the session file (which for debian, the session files are
saved in /var/lib/php5).
A workaround I came up with is, at the end of the script do something like this:
$session_temp = $_SESSION;
session_write_close();
session_start();
$_SESSION = $session_temp;
session_write_close();
This is a bit crazy but it works. (I tried just using session_write_close(); without success. The
important bit seems to be restarting the session using session_start after closing the session using
session_write_close()).
I suspect that using the mm extension would avoid this problem, but it is not always available.
Alternatively, writing ones own session handler and storing the data in a database may avoid the
problem.
-------
Noticed a post on the main session manual page by "rciq at tlen dot pl"
who said:
> Don't do anything like:
> $_SESSION = $some_array;
> My php5.0.4 session stops without saving after such operations.
Not sure if this would apply to $_SESSION['foo'] = $some_array as well. However the fix I
mentioned at the begging will do the right thing regardless.