Session Timeout Redirect in a php app

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • johnhaag90
    New Member
    • Jul 2015
    • 1

    Session Timeout Redirect in a php app

    So, I've written some code that kills the session on timeout, but it will not redirect to the login screen unless I try to navigate to another page in the app. Any suggestions?

    Code:
    		if(isset($_SESSION['start']) ) {
    		$session_life = time() - $_SESSION['start'];
    		if($session_life > $inactive) {
    		$_SESSION = array();
    		$session_destroy();
    		header('Location:login.php');
    		$timedout = '1';
    
    	}
    }
    Last edited by Rabbit; Jul 17 '15, 03:56 PM. Reason: Please use [code] and [/code] tags when posting code or formatted data.
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    1) why not leave session timeout to PHP? it has a GC for timed-out sessions.

    2) redirects not working are 99% due to having output before it. enable error reporting and error display to show error messages concerning that problem.

    Comment

    Working...