wilna Posted March 26, 2010 Share Posted March 26, 2010 Hi, I have been searching the forums & google but still am strugling. If the user has been inactive for 10 mins I want the page to automatically throw them out. At this stage my script throws them out but only if they have been inactive for 10 mins and then click on something. My code looks like this: // 10 mins in seconds $inactive = 600; $session_life = time() - $_session['timeout']; if($session_life > $inactive) { session_destroy(); header("Location: http://www.mydomain.com/login_new1.htm"); } $_session['timeout']=time(); Link to comment https://forums.phpfreaks.com/topic/196573-php-timeout-and-redirect/ Share on other sites More sharing options...
xcandiottix Posted March 26, 2010 Share Posted March 26, 2010 // 10 mins in seconds $inactive = 600; $session_life = time() - $_session['timeout']; if($session_life > $inactive) { session_destroy(); header("Location: http://www.mydomain.com/login_new1.htm"); } $_session['timeout']=time(); to // 10 mins in seconds $inactive = 600; $_session['timeout']=time(); $session_life = time() - $_session['timeout']; if($session_life > $inactive) { session_destroy(); header("Location: http://www.mydomain.com/login_new1.htm"); } ? modify: I didn't pay attention that you said the code isss working already. It just seemed to me that you'd have to set your $_session['timeout'] before you can check it in $session_life. Anyway, the reason why it works when they click on something is because the php starts working again. When a visitor logs in currently, the php checks your code on the first load and since the > condition isn't met it skips it and never come back again until the php is reactivated. I'm not sure on this, but I'd guess you need a loop running. Something like: $i=0; $session_life = time() - $_session['timeout']; $_session['timeout']=time(); //or these two visa versa like i had it If($i<10){ $inactive = 600; if($session_life > $inactive) { session_destroy(); header("Location: http://www.mydomain.com/login_new1.htm"); } $i++; $i = 0; } This would keep the loop on going, constantly checking the time. Totally just a guess tho. Link to comment https://forums.phpfreaks.com/topic/196573-php-timeout-and-redirect/#findComment-1032098 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.