Jump to content

Session experation


The Little Guy

Recommended Posts

Why are my sessions not expiring?

 

I have tryed 2 things

 

1:

session_cache_limiter();
session_cache_expire(1);
session_start();

 

2:

ini_set("session.gc_maxlifetime", "60");
session_start();

 

Could the problem be that is that I am placeing it in a global file, which is included on every page?

Link to comment
Share on other sites

what do you mean by "not expiring". are they always running? even when you close the browser and wait then go back on....

No, they expire when the browser closes.

 

I want them to expire 15 minutes after inactivity, so if the user refreshes the page after 15 minutes of doing nothing, It should ask him/her to log back in.

Link to comment
Share on other sites

so.... What I could do is make a function, that has a page view time, and then when the user views the page again, match against the current time, then...

 

either destroy the sessions, if the time is over 15 minutes, or

refresh the session, to the current time, if it is under 15 minutes.

 

(I feel that would be better than using a database.)

Link to comment
Share on other sites

OK... Here is what I came up with. Works great, and if you want to use it, be my guest:

 

<?php
# Log a user Out
function logOut(){
$_SESSION = array();
if (isset($_COOKIE[session_name()])) {
	setcookie(session_name(), '', time()-42000, '/');
}
session_destroy();
}

# Session Logout after in activity
function sessionX(){
$logLength = 900;  // Max login, in seconds
$ctime = strtotime("now");
if(!isset($_SESSION['sessionX'])){
	$_SESSION['sessionX'] = $ctime;
}else{
	if((strtotime("now") - $_SESSION['sessionX']) > $logLength){
		logOut();
		header("Location: logout_page.php");  //location of your log out success page.
		exit;
	}else{
		$_SESSION['sessionX'] = $ctime;
	}
}
}
# Run Session logout check
sessionX();
?>

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.