• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 251
  • Last Modified:

how to expire the PHP session after some predefined time

Hi friends,
This is very simple question
I want to expirer the session for the web page if user has not fill the data or take any action on the web page for the more than 1 minute .so can u tell me how i will do this
I know u  can unset or destroy the session variables by using session unset function but Here I want to unset the values at run time and that to be only if user has not taken any action on web page for 1 min  so plz tell how i will do the same using PHP  
thanks in advance
0
vvs
Asked:
vvs
  • 2
  • 2
2 Solutions
 
ThomasFrankeCommented:
You can use unset()  to unset a variable.

unset($_SESSION['UserValue']);    // unsets the session variable 'UserValue'

see http://www.php.net/manual/en/function.unset.php for more information on unset.

It might be a good idea not to rely on session expiration etc.
You could store the time of the last user request within the users session. Then
evaluate the time difference between the last request and the current one. If
the dime difference is greater than 60 secs display an approbiate error message.

0
 
DBBCommented:
Hi,


Check out this tutorial, it explains step by step and includes code:-

http://www.phpfreaks.com/tutorials/77/0.php

Dbb
0
 
ThomasFrankeCommented:
Agreed.
0
 
DBBCommented:
Also agreed.
0

Featured Post

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now