Alex Rivera | Logout

PHP Session data not being saved

Asked 2008-10-01T01:57:49.127
58

I have one of those "I swear I didn't touch the server" situations. I honestly didn't touch any of the php scripts. The problem I am having is that php data is not being saved across different pages or page refreshes. I know a new session is being created correctly because I can set a session variable (e.g. $_SESSION['foo'] = "foo" and print it back out on the same page just fine. But when I try to use that same variable on another page it is not set! Is there any php functions or information I can use on my hosts server to see what is going on?

Here is an example script that does not work on my hosts' server as of right now:

<?php
session_start();
if(isset($_SESSION['views']))
    $_SESSION['views'] = $_SESSION['views']+ 1;
else
    $_SESSION['views'] = 1;

echo "views = ". $_SESSION['views'];
echo '<p><a href="page1.php">Refresh</a></p>';
?>

The 'views' variable never gets incremented after doing a page refresh. I'm thinking this is a problem on their side, but I wanted to make sure I'm not a complete idiot first.

Here is the phpinfo() for my hosts' server (PHP Version 4.4.7): alt text

Edit
Report

4 Answers

13

Check to make sure you are not mixing https:// with http://. Session variables do not flow between secure and insecure sessions.

answered 2011-10-25T01:38:28.447
2

If you set a session in php5, then try to read it on a php4 page, it might not look in the correct place! Make the pages the same php version or set the session_path.

answered 2010-04-10T14:50:58.340
1

Check if you are using session_write_close(); anywhere, I was using this right after another session and then trying to write to the session again and it wasn't working.. so just comment that sh*t out

answered 2009-07-31T11:43:56.333
1

Edit your php.ini.
I think the value of session.gc_probability is 1, so set it to 0.

session.gc_probability=0
answered 2012-09-23T18:01:24.790

Your Answer