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
https://forums.phpfreaks.com/topic/57452-session-experation/
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
https://forums.phpfreaks.com/topic/57452-session-experation/#findComment-284625
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
https://forums.phpfreaks.com/topic/57452-session-experation/#findComment-285209
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
https://forums.phpfreaks.com/topic/57452-session-experation/#findComment-285256
Share on other sites

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.