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

Link to comment
Share on other sites

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

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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