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>