My PHP sessions are being created but $_SESSION
variables are not being written to the session file.
I have three test PHP pages here that I'm using to diagnose this problem:
test_a.html
:
<html>
<body>
<form action='test_b.php' method='post'>
Put something here:
<input type='text' name='saveme' />
<input type='submit' value='Go!' />
</form>
</body>
</html>
test_b.php
:
<?php
session_start();
$_SESSION['saveme']=$_POST['saveme'];
echo "Here's what you wrote:<br>".$_SESSION['saveme']."<br>".
"<a href='test_c.php'>Take me to the final check</a><br>";
echo "And here's your session_id: ".session_id();
session_write_close();
?>
test_c.php
:
<?php
session_start();
echo "Here's what you wrote (maybe?):<br>".$_SESSION['saveme']."<br>".
"You should also see saveme below:<br>";
foreach ($_SESSION as $key=>$val)
echo $key." ".$val."<br>";
echo "And here's your session_id: ".session_id();
?>
When opening test_a.html
and typing in anything to the textbox and hitting Go!, it will show up correctly on test_b.php
(when it is set and recalled from memory) but it is not shown on test_c.php
.
The session_id
is set and shows to be the same. The cookie is stored correctly. The session file is created correctly in the filesystem, but is not written to and remains a zero-byte file.
Sessions are now not being written on any pages of my site (despite working for well over a year up to this point) so typos in these code snippets (if any) are likely irrelevant.
Things I've checked:
- The session storage directory is writeable and the disk has plenty of storage
session_start
is always successful (and there is nothing before it)- The
session_id
is created correctly and is the same on both pages - The session cookie is created with the correct
session_id
session.use_cookies
andsession.use_only_cookies
are on- Register globals is off
- Cookies are enabled
- Cleared the
/tmp
directory to reduce possibility of filesystem issues - Tried storing the session data in memory (didn't work)
- Tried changing the session file location (didn't work)
- Tested on Chrome & Firefox
Ideas?