Livewire pointed out problems with using session.gc_maxlifetime and the cookies approach.
That was good but it still presented the problem of actually blocking out the real user.
So I devised a plan to use javascript to run some php that, instead of looking to see if it should log the user off, looked to see it it could keep the user logged on. Therefore, as long as the real user left the tab open, the javascript would keep updating a time stamp held in a session var, but if they navigate away, or close the browser tab, the javascript wouldn't run, and the timestamp wouldnt be refreshed. Then the next action anyone took on my site would run through some php that comes before any html or headers would log them out.
Of course, this leaves the obvious problem of public libraries and such where someone could come along and use the users account if they forget to close the tab or browser. Ironically this is the problem most features like a short session lifetime look to circumvent in the first place. But im ok with that. The user should have some responsibility with their own account. I mean to access it publicly and then just leave it open and walk away, when they have something invested in the account? I'm not worried about that. What i'm worried about is hackings eavesdropping in on my sessions, and/or being able to use fixation, etc...
WEBPAGE:
Code:
<?PHP
session_start();
if(!isset($_SESSION['freshTime']) || time() - $_SESSION['freshTime'] > 400)
{
header("location: Logout.php");
exit();
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript">
function refreshNow()
{
document.getElementById('security-code').innerHTML = "<iframe src='refreshTime.php'></iframe>";
}
function MyOnLoad()
{
refreshNow();
setInterval("refreshNow()", 300000);
}
</script>
</head>
<body onload="MyOnLoad();">
<div style="display:none" id="security-code"> </div>
<div> content... content... content... content... </div>
</body>
</html>
refreshTime.php
Code:
<?PHP
session_start();
$_SESSION['freshTime'] = time();
?>
I'd be grateful for any critiquing or improvement upon this code.
Thanks all.