Skip to content

Instantly share code, notes, and snippets.

@dextel2
Forked from psdtohtml5/gist:6090113
Last active November 27, 2017 18:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dextel2/43b624779cc1b9441e3f39bb3f0e8ba6 to your computer and use it in GitHub Desktop.
Save dextel2/43b624779cc1b9441e3f39bb3f0e8ba6 to your computer and use it in GitHub Desktop.
PHP : 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['email']>$idletime){
session_destroy();
session_unset();
header('Location: ../index.php');// relocating user to home page
}else{
$_SESSION['email']=time();
}
//on session creation
$_SESSION['email']=time();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment