Session Destroy For While User Stay In One Page Without Any Action?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sureshmca
    New Member
    • Dec 2012
    • 1

    Session Destroy For While User Stay In One Page Without Any Action?

    I 'd like to session destroy when that user for 1 hours dont dont press any key or scroll page and dont go to another or in other words stay in one page for a alot of time
  • Arjuntcs
    New Member
    • Dec 2012
    • 4

    #2
    I am thinking session_unset()

    check this out!

    Comment

    • Arjuntcs
      New Member
      • Dec 2012
      • 4

      #3
      or even some variant of this should help
      Code:
      session_start();
      
      
      // set timeout period in seconds
      $inactive = 600;
      // check to see if $_SESSION['timeout'] is set
      if(isset($_SESSION['timeout']) ) {
      	$session_life = time() - $_SESSION['timeout'];
      	if($session_life > $inactive)
              { session_destroy(); header("Location: logoutpage.php"); }
      }
      $_SESSION['timeout'] = time();


      Note the session_destroy () in this example, it destroys all the session vars as opposed to session_unset which simply clears them.
      Last edited by Arjuntcs; Dec 6 '12, 08:49 AM. Reason: Explanation

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        I 'd like to session destroy when that user for 1 hours dont dont press any key or scroll page […]
        PHP will never get any note of this, since that are client side UI actions that do not make it to the server.

        essentially, you do not even need to do anything except setting the session GC to the appropriate values (the session destroys itself after a set time, also called session timeout).

        Comment

        Working...