squiblo Posted July 24, 2009 Share Posted July 24, 2009 will the redirect and timeout parts of the script work, ive basically put two together, and i dont want to wait 20mins to see if it has worked <?php session_start(); if(isset($_SESSION['myusername'])){ header("location:profile.php"); // 20 mins in seconds $inactive = 1200; $session_life = time() - $_session['timeout']; if($session_life > $inactive){ header("Location: logoutpage.php"); } S_session['timeout']=time(); exit; ?> Quote Link to comment https://forums.phpfreaks.com/topic/167276-will-this-script-work/ Share on other sites More sharing options...
Maq Posted July 24, 2009 Share Posted July 24, 2009 Then change it to 3 seconds... Quote Link to comment https://forums.phpfreaks.com/topic/167276-will-this-script-work/#findComment-881967 Share on other sites More sharing options...
haku Posted July 24, 2009 Share Posted July 24, 2009 Or change it to like 12 hours, go to bed, go to the store, scratch your bum, then check it. Quote Link to comment https://forums.phpfreaks.com/topic/167276-will-this-script-work/#findComment-881969 Share on other sites More sharing options...
squiblo Posted July 24, 2009 Author Share Posted July 24, 2009 i changed to 3 seconds and it doesnt work, also how do i view my errors? im using "Core FTP" if that even makes a difference Quote Link to comment https://forums.phpfreaks.com/topic/167276-will-this-script-work/#findComment-881974 Share on other sites More sharing options...
haku Posted July 24, 2009 Share Posted July 24, 2009 Look at Maq's signature. That's how you display errors. Quote Link to comment https://forums.phpfreaks.com/topic/167276-will-this-script-work/#findComment-881975 Share on other sites More sharing options...
squiblo Posted July 24, 2009 Author Share Posted July 24, 2009 can u place it anywhere in the script? Quote Link to comment https://forums.phpfreaks.com/topic/167276-will-this-script-work/#findComment-881977 Share on other sites More sharing options...
haku Posted July 24, 2009 Share Posted July 24, 2009 Yep, but it's probably best if you place it before anywhere an error will potentially occur. Quote Link to comment https://forums.phpfreaks.com/topic/167276-will-this-script-work/#findComment-881980 Share on other sites More sharing options...
Maq Posted July 24, 2009 Share Posted July 24, 2009 Just put it at the top directly after your opening Quote Link to comment https://forums.phpfreaks.com/topic/167276-will-this-script-work/#findComment-881981 Share on other sites More sharing options...
squiblo Posted July 24, 2009 Author Share Posted July 24, 2009 i cant find what is wrong with it still Quote Link to comment https://forums.phpfreaks.com/topic/167276-will-this-script-work/#findComment-881999 Share on other sites More sharing options...
haku Posted July 24, 2009 Share Posted July 24, 2009 I'd say the problem is that "it doesnt work". Quote Link to comment https://forums.phpfreaks.com/topic/167276-will-this-script-work/#findComment-882000 Share on other sites More sharing options...
Maq Posted July 24, 2009 Share Posted July 24, 2009 Echo out your session array to see what's actually in it. print_r($_SESSION); (after your session_start(); line) Quote Link to comment https://forums.phpfreaks.com/topic/167276-will-this-script-work/#findComment-882001 Share on other sites More sharing options...
squiblo Posted July 24, 2009 Author Share Posted July 24, 2009 this code: <?php session_start(); print_r($_SESSION); if(!isset($_SESSION['myusername'])){ header("location:index.php"); // set timeout period in seconds $inactive = 600; // check to see if $_SESSION['timeout'] is set if(isset($_SESSION['timeout']) ) { $session_life = time() - $_SESSION['start']; if($session_life > $inactive) { session_destroy(); header("Location: logout.php"); } } $_SESSION['timeout'] = time(); exit; } ?> gave: Array ( [timeout] => 1248446158 ) Quote Link to comment https://forums.phpfreaks.com/topic/167276-will-this-script-work/#findComment-882009 Share on other sites More sharing options...
squiblo Posted July 24, 2009 Author Share Posted July 24, 2009 i get Array ( [timeout] => 1248446158 ) then if i refresh page i get Array () refresh again to get Array ( [timeout] => (different number)) Quote Link to comment https://forums.phpfreaks.com/topic/167276-will-this-script-work/#findComment-882011 Share on other sites More sharing options...
Maq Posted July 24, 2009 Share Posted July 24, 2009 The only thing your script should be doing is if $_SESSION['myusername'] is not set then it redirects to index.php. What exactly is not working? Quote Link to comment https://forums.phpfreaks.com/topic/167276-will-this-script-work/#findComment-882013 Share on other sites More sharing options...
KevinM1 Posted July 24, 2009 Share Posted July 24, 2009 i get Array ( [timeout] => 1248446158 ) then if i refresh page i get Array () refresh again to get Array ( [timeout] => (different number)) That's because the time() function returns the current time. Unless time itself stops, the number will always change. And, in that circumstance, you have bigger problems than your script failing. Quote Link to comment https://forums.phpfreaks.com/topic/167276-will-this-script-work/#findComment-882015 Share on other sites More sharing options...
squiblo Posted July 24, 2009 Author Share Posted July 24, 2009 the redirecting part is fine i can do that, i do not if the time code is correct or even in the correct place Quote Link to comment https://forums.phpfreaks.com/topic/167276-will-this-script-work/#findComment-882016 Share on other sites More sharing options...
squiblo Posted July 24, 2009 Author Share Posted July 24, 2009 any1 know how to correct it? Quote Link to comment https://forums.phpfreaks.com/topic/167276-will-this-script-work/#findComment-882047 Share on other sites More sharing options...
Maq Posted July 24, 2009 Share Posted July 24, 2009 Looking back on it, you've posted 2 different scripts. Which is it? Quote Link to comment https://forums.phpfreaks.com/topic/167276-will-this-script-work/#findComment-882050 Share on other sites More sharing options...
squiblo Posted July 24, 2009 Author Share Posted July 24, 2009 this is the script i have now <?php session_start(); print_r($_SESSION); if(!isset($_SESSION['myusername'])){ header("location:index.php"); // set timeout period in seconds $inactive = 600; // check to see if $_SESSION['timeout'] is set if(isset($_SESSION['timeout']) ) { $session_life = time() - $_SESSION['start']; if($session_life > $inactive) { session_destroy(); header("Location: logout.php"); } } $_SESSION['timeout'] = time(); exit; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/167276-will-this-script-work/#findComment-882054 Share on other sites More sharing options...
Maq Posted July 24, 2009 Share Posted July 24, 2009 I'm not sure what you're trying to do. If $_SESSION['myusername'] is not set then it redirects to "index.php". If it is set then it does nothing... The other code wouldn't even be executed. Quote Link to comment https://forums.phpfreaks.com/topic/167276-will-this-script-work/#findComment-882059 Share on other sites More sharing options...
squiblo Posted July 24, 2009 Author Share Posted July 24, 2009 where im my script should i put the timeout part becauce im not sure Quote Link to comment https://forums.phpfreaks.com/topic/167276-will-this-script-work/#findComment-882061 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.