Re: Multiple sessions open at same time, is it possible?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 2 Mar 2008, at 15:59, Richard wrote:
Stut a écrit :
On 2 Mar 2008, at 15:28, Richard wrote:
However, is there a way to limit the session stay alive time for just one variable ?

If for example, if a user has not done anything in his members area for more than 30 minutes I would like to be able to reset his password, but I do not want to reset the cart. Do I have to program this seperatly in PHP (IE set a session varibale $_SESSION['last_time'] = time(); and on each page loads :

if ( time() - $_SESSION[last_time] > 1800) {
  $_SESSION['password'] = array();
else {    $_SESSION['last_time'] = time()
  }
...

Or is there a better way to do this?

There is no built-in mechanism for this so you need to implement your own as above. Personally I would store it as an expiry time rather than the current time, but whatever floats ya boat.

Sorry, I only know how to use current time, just for my personal interest, how would you use expiry time ? I've looked around a bit and can't work out how you would do this without using the current time...


It's really not rocket science...

if ($_SESSION['expiry'] < time())
{
    $_SESSION['password'] = array();
}
else
{
    // Password expires in 30 minutes
    $_SESSION['expiry'] = time() + 1800;
}

Just curious... why are you setting the password to an empty array? You'd probably be better off unset'ing it so you can use isset to check for it.

-Stut

--
http://stut.net/
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux