I'm trying to implement sessions on my site for the first time.
For security reasons I have register_globals turned OFF.
What happens is that the session variable don't seem to survive from one page to another. The value of the session variable resets.
For simplicity I have reduced the code but it still won't work - running on WinNT + PHP 4.2.3, behind a firewall or two.
Instead of updating the userid-variable in the session-file it actually re-registers the variable with the new value from the second page.
First: another example (from php.net's session manual!) that actually do NOT update the variable's value. Instead it registers a new session each time I update the page:
<?php
session_start();
if (!isset($SESSION['count']))
{
$SESSION['count'] = 0;
}
else
{
$_SESSION['count']++;
}
?>
And here comes the "two-page" example:
Page 1
<?
// Start session before all other headers!
session_start();
// displaying if it's set and it's value, before setting, shows 0 and 0
printf("isset: %d value: %d<BR>", isset($SESSION['userid']), $SESSION['userid'] );
// setting it
$_SESSION['userid'] = 2;
// displaying again, now shows 1 and 2
printf("isset: %d value: %d<BR>", isset($SESSION['userid']), $SESSION['userid'] );
?>
<P><A HREF="sess2.php">S2</A>
Page 2
<?
// Start session before all other headers!
session_start();
// displaying if it's set and it's value, shows 0 and 0 again...should be 1 and 2
printf("isset: %d value: %d<BR>", isset($SESSION['userid']), $SESSION['userid'] );
// setting it again
$_SESSION['userid'] = 3;
// displaying again - shows 1 and 3, but dies again when I jump back
printf("isset: %d value: %d<BR>", isset($SESSION['userid']), $SESSION['userid'] );
?>
<P><A HREF="sess1.php">S1</A>