Jump to content

Can anyone advise whats wrong with this start/destroy session script?


rich_traff

Recommended Posts

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...

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

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");

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.