Wednesday 8 November 2017

PHP Code for Automatic Expire Login Session

Hey Friends, Today I am going to describe the PHP Code regarding automatic expire session login in a website. It is very easy to expire session for login for sometime or specified time.
   <?php
//on pageload
session_start();

$idletime=60;//after 60 seconds the user gets logged out

if (time()-$_SESSION['timestamp']>$idletime){
session_destroy();
session_unset();
}else{
$_SESSION['timestamp']=time();
}

//on session creation
$_SESSION['timestamp']=time();

No comments:

Comments System