Forum Moderators: coopster

Message Too Old, No Replies

Session variables expiration?

strange behaviour

         

Tetsuo

10:51 am on Jan 15, 2003 (gmt 0)

10+ Year Member



Hi,

Sometimes, on the page2.php, when I click RELOAD button after about 10 sec, the variables $user and $pw are not displayed as if they did not exist anymore.

("sometimes", i.e. "yesterday it works fine but today, the problem appeared"...)

Here is the code I'm using (two pages, PHP 4.0.4):

// PAGE1.php
<?
session_start();

session_register("user");
session_register("pw");

$user = "hello";
$pw = "world";

?>

<H3>Session Variables Initialized</H3>
$user = <? echo $user;?><br>
$pw = <? echo $pw;?><br>

<br>

Go to <a href="http://whatever.com/page2.php">next page</a>

// PAGE2.php

<?
session_start();

if ($go == "RELOAD") {
Header("Location: [whatever.com...]
exit;
}
else if ($go == "RESET") {
session_unregister("user");
session_unregister("pw");
}
else if ($go == "FIRST") {
Header("Location: [whatever.com...]
exit;
}

?>
<H3>Second page</H3>
$user = <? echo $user;?><br>
$pw = <? echo $pw;?><br>

<br>

<form action=<?echo $PHP_SELF;?>>
<input type=submit name=go value=RELOAD>
<input type=submit name=go value=RESET>
<input type=submit name=go value=FIRST>
</form>

Does anyone have an idea if some configuration parameters are involved or ...?

Thanx

lazerzubb

12:16 pm on Jan 15, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome to WebmasterWorld [webmasterworld.com]
It might help if you set the specific time the session is supposed to live?

Tetsuo

2:58 pm on Jan 15, 2003 (gmt 0)

10+ Year Member



I think so... But I did not find the parameters to set to have a specific lifetime for my session. Is it a Apache parameter or something else?

Maybe "session.gc_maxlifetime"? I don't think the "Timeout Keep-Alive" HTTP parameter is involved but I may be in a wrong way! :-)

Tetsuo

8:57 am on Jan 20, 2003 (gmt 0)

10+ Year Member



I tried several configuration of my php.ini but it still does not work (after a few seconds, my session variables are unset...)

session.use_cookies = 1
session.name = PHPSESSID
session.auto_start = 0
session.cookie_lifetime = 0
session.cookie_path = /
session.cookie_domain =
session.serialize_handler = php
session.gc_probability = 1
session.gc_maxlifetime = 1440

Here, I'm using cookies that expires only when the browser is restarted. So, I should keep my session variables?!

Did anyone meet the same problem?

Tetsuo

10:07 am on Jan 20, 2003 (gmt 0)

10+ Year Member



A solution that seems to work is to send the $PHPSESSID with POST or GET each time the page is reloaded.

<input type=hidden name=PHPSESSID value=<? echo $PHPSESSID;?>>