ryanemitchell
4/9/2015 - 2:31 PM

Auto expire session / Auto logout after specific time

Auto expire session / Auto logout after specific 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();