rich_traff Posted June 17, 2010 Share Posted June 17, 2010 Can anyone tell me why the following code isn't working? <?php //Start session session_start(); // set timeout period in seconds $inactive = 600; // check to see if $_SESSION['timeout'] is set if(isset($_SESSION['timeout']) ) { $session_life = time() - $_SESSION['timeout']; if($session_life > $inactive) { session_destroy(); header($_SERVER['DOCUMENT_ROOT']."/clientlogin/logout.php"); } } $_SESSION['timeout'] = time(); //Check whether the session variable SESS_MEMBER_ID is present or not if(!isset($_SESSION['SESS_MEMBER_ID']) || (trim($_SESSION['SESS_MEMBER_ID']) == '')) { header("location: access-denied.php"); exit(); } ?> Its to log a user out when they've been inactive for a length of time. - the script is working in the fact that after the allotted time the session seems to be destroyed, however - instead of redirecting the user to logout.php it is giving the following error [an error occurred while processing this directive] any advise would be appreciated... Quote Link to comment https://forums.phpfreaks.com/topic/205103-can-anyone-advise-whats-wrong-with-this-startdestroy-session-script/ Share on other sites More sharing options...
swisse Posted June 17, 2010 Share Posted June 17, 2010 hi rich_traff, the line: header($_SERVER['DOCUMENT_ROOT']."/clientlogin/logout.php") is missing the code location. That's why it can't redirect to the logout script. swisse Quote Link to comment https://forums.phpfreaks.com/topic/205103-can-anyone-advise-whats-wrong-with-this-startdestroy-session-script/#findComment-1073655 Share on other sites More sharing options...
rich_traff Posted June 18, 2010 Author Share Posted June 18, 2010 Hi Swisse, can you explain what you mean by the code location? i've used this line before to call other files with no problems ($_SERVER['DOCUMENT_ROOT']."/clientlogin/logout.php") or are you referring to something else? thanks Quote Link to comment https://forums.phpfreaks.com/topic/205103-can-anyone-advise-whats-wrong-with-this-startdestroy-session-script/#findComment-1073864 Share on other sites More sharing options...
mentalist Posted June 18, 2010 Share Posted June 18, 2010 header Quote Link to comment https://forums.phpfreaks.com/topic/205103-can-anyone-advise-whats-wrong-with-this-startdestroy-session-script/#findComment-1073866 Share on other sites More sharing options...
PFMaBiSmAd Posted June 18, 2010 Share Posted June 18, 2010 You might have used code like that in an include()/require() statement (which is processed on the server), but $_SERVER['DOCUMENT_ROOT'] is a file system path and cannot be used in a header() redirect AND your header() redirect is also invalid. A header redirect is coded like - header("Location: http://www.example.com/your_path/your_file.php"); Quote Link to comment https://forums.phpfreaks.com/topic/205103-can-anyone-advise-whats-wrong-with-this-startdestroy-session-script/#findComment-1073867 Share on other sites More sharing options...
mentalist Posted June 18, 2010 Share Posted June 18, 2010 Are you thinking of $_SERVER['HTTP_HOST'] and not $_SERVER['DOCUMENT_ROOT'] ? Quote Link to comment https://forums.phpfreaks.com/topic/205103-can-anyone-advise-whats-wrong-with-this-startdestroy-session-script/#findComment-1073869 Share on other sites More sharing options...
rich_traff Posted June 18, 2010 Author Share Posted June 18, 2010 Ah right, i see... many thanks, all working fine now Quote Link to comment https://forums.phpfreaks.com/topic/205103-can-anyone-advise-whats-wrong-with-this-startdestroy-session-script/#findComment-1073872 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.