Session Timeout Problem
Posted: Thu Sep 13, 2007 1:44 am
hi all,
I am facing 2 problems regarding Sessions.
problem1:
I have created a session variable $_SESSION['first'] on first file, "session1.php".
Then I print its value on another page named "session2.php".
I need this variable's value to be expired or destroyed after 30 seconds automatically.
For that purpose I've changed a setting in php.ini as under
Here comes the problem, I've waited for 35 seconds on "session2.php", then refreshed the page but alas! I still get the value of Session variable. Can anybody tell me what I am doing wrong here? Or should I have to do some thing else ?
problem2:
I wanted to change the session time out value by code, so, I used following code to change the time in "set_session.php" file.
This is also not working for me.
When I go to some other file e.g) "session2.php" it shows me the time which is set in php.ini, it did not change the time using php code.
can any body tell me how can i do that ?
the code for all of three files are as under:
session1.php
session2.php
set_session.php
I am facing 2 problems regarding Sessions.
problem1:
I have created a session variable $_SESSION['first'] on first file, "session1.php".
Then I print its value on another page named "session2.php".
I need this variable's value to be expired or destroyed after 30 seconds automatically.
For that purpose I've changed a setting in php.ini as under
Code: Select all
session.gc_maxlifetime = 30problem2:
I wanted to change the session time out value by code, so, I used following code to change the time in "set_session.php" file.
Code: Select all
ini_set('session.gc_maxlifetime',25);When I go to some other file e.g) "session2.php" it shows me the time which is set in php.ini, it did not change the time using php code.
can any body tell me how can i do that ?
the code for all of three files are as under:
session1.php
Code: Select all
<?
session_start();
$currentTimeoutInSecs = ini_get("session.gc_maxlifetime");
print("TimeOut: ".$currentTimeoutInSecs." sec<br>");
$_SESSION['first']="Value of First Session";
print("sess val : ".$_SESSION['first']);
?>
<br />
<br />
<a href="session2.php">session2</a> | <a href="set_session.php">set session</a>Code: Select all
<?
session_start();
$currentTimeoutInSecs = ini_get("session.gc_maxlifetime");
print("TimeOut: ".$currentTimeoutInSecs." sec<br>");
print("sess val : ".$_SESSION['first']);
?>
<br />
<br />
<a href="session1.php">session1</a> | <a href="set_session.php">set session</a>Code: Select all
<?
session_start();
ini_set('session.gc_maxlifetime',30);
$currentTimeoutInSecs = ini_get("session.gc_maxlifetime");
print("TimeOut: ".$currentTimeoutInSecs." sec<br>");
print("sess val : ".$_SESSION['first']);
?>
<br />
<br />
<a href="session1.php">session1</a> | <a href="session2.php">session2</a>