Page 1 of 1

Session Variables Not Being Preserved

Posted: Thu Mar 19, 2009 1:43 pm
by corwin
I am unable to use session variables on a page other than the one where they are set, IOW they act like non-session variables. I have found a similar question posted in half a dozen other similar fora, but the answer in those other cases always turns out not to apply.

Here are my files:

sess1.php

Code: Select all

<?php
session_start();
    
session_register("userid");
session_register("textvar");
   
$_SESSION['userid'] = 10333 ;
$_SESSION['textvar'] = TextVariable ;
    
echo "<p>User ID is: " . $_SESSION['userid'] . "</p>" ;
echo "<p>Another variable is: " . $_SESSION['textvar'] . "</p>" ;
?>
<p>Go to the <a href="sess2.php">next page</a>.</p>
and,
sess2.php

Code: Select all

<?php
session_start();
    
echo "<p>The userid session variable is: " . $_SESSION['userid'] . "</p>";
echo "<p>The other session variable is: " . $_SESSION['newvar']. "</p> ";
?>
The browser output in each case is:

sess1.php

Code: Select all

User ID is: 10333
 
Another variable is: TextVariable
 
Go to the [next page].
 
and,
sess2.php

Code: Select all

The userid session variable is:
 
The other session variable is:
 
Go to the [last page].
A few things it is NOT:
  • I do have session_start() at the top of both files.
  • The variables directory is writable, and the session variables are showing up there. (I have about a hundred little files called sess_b62<snip>, that have this inside: 'userid|i:10333;textvar|s:12:"TextVariable";'.)
  • phpinfo() tells me that the php.ini file is being read correctly and the lifetime is set to the default, 0, i.e. until the browser is closed.
I'm at my wit's end. Any suggestions?

Thanks so much.

Re: Session Variables Not Being Preserved

Posted: Thu Mar 19, 2009 4:44 pm
by atonalpanic
Make sure your browser accepts cookies?

Re: Session Variables Not Being Preserved

Posted: Thu Mar 19, 2009 8:48 pm
by rcastera
Hey,

Try removing line 4 and 5 in sess1.php and give it a shot. And don't forget atonalpanic's recommendation of making sure that your browser is accepting cookies.

http://www.php.net/session_register

Cheers!

Re: Session Variables Not Being Preserved

Posted: Fri Mar 20, 2009 5:28 pm
by corwin
Okay, I've discovered that the session IDs returned on each page are different, so for some reason the session ID isn't being retained from page to page. Great. Now what?