webguync Posted March 16, 2010 Share Posted March 16, 2010 anyone know what might be causing my redirect to not work in my session ending/logout code. The session ending part seems to work, but not the automatic redirect back to the login page. I know the session ending works, b/c when I refresh the page I go back to the login screen. <?php session_start(); if(!session_is_registered("session_count")) { $session_count = 0; $session_start = time(); $_SESSION['session_count']=$session_count; $_SESSION['session_start']=$session_start; } else { $session_count++; } $session_timeout = 30; // expires after 30 seconds $session_duration = time() - $session_start; if ($session_duration > $session_timeout) { session_unset(); session_destroy(); $_SESSION = array(); header("Location: StudentLogin.php"); // Redirect to Login Page } else { $session_start = time(); $_SESSION['session_start']=$session_start; } Quote Link to comment Share on other sites More sharing options...
nafetski Posted March 16, 2010 Share Posted March 16, 2010 Just making sure... If you reload the page, and it sends you to the login page (after the session has expired) then PHP is doing it's job properly. If you want to redirect the browser (without the user having to go to a new page, or refresh) then you will want to redirect via JS or a meta redirect. That, or have an ajax request hit the server, check the session, and based on that redirect. Either way, if javascript is turned off your options on automatically redirecting based on a timeout are limited. If that's not what's happening, then I appologize and will be happy to help you investigate further! Quote Link to comment Share on other sites More sharing options...
webguync Posted March 16, 2010 Author Share Posted March 16, 2010 yep you got it, so I guess the PHP code is working. Can I just add meta direct to the current code, if so would it just need to replace : header("Location: StudentLogin.php"); // Redirect to Login Page with... <meta http-equiv='refresh' content='30'; url='StudentLogin.php'> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.