Jump to content

Recommended Posts

I am working on timed session for my project. So they have X minuets per pages to indicate some activity before the systems logs them out. Here is how I am going about this:

 

At the login function: set time limit, store session time in a session variable.

 

In main.php (included on every page): check time with expiredTime() function

 

if this returns false, then call the updateTime() function, else logout.

 

Here are my functions:

function startTime($min){ //Starts the time clock (TC), should only be used in the loginAdmin and updateTime functions.
$min *= 60;
if(!isset($_SESSION['~TC:Min']) || $_SESSION['~TC:Min'] != $min)
	$_SESSION['~TC:Min'] = $min;

$_SESSION['~TC:Time'] = time() + $_SESSION['~TC:Min'];
}
function updateTime(){
startTime($_SESSION['~TC:Min']); //No need to do the same thing twice. Resets the clock per page.
}
function expriedTime(){//True if time has expired; false otherwise.
 return time() > $_SESSION['~TC:Time'];
}

Link to comment
https://forums.phpfreaks.com/topic/200316-is-my-logic-correct/
Share on other sites

I revised my functions like so:

function startTime($min){ //Starts the time clock (TC), should only be used in the loginAdmin and updateTime functions.
$min *= 60;
if(!isset($_SESSION['~TC:Min']) || $_SESSION['~TC:Min'] != $min)
	$_SESSION['~TC:Min'] = $min;
//$_SESSION['~TC:Time'] = time() + $_SESSION['~TC:Min'];
updateTime();
}
function updateTime(){
//startTime($_SESSION['~TC:Min']); //No need to do the same thing twice. Resets the clock per page.
$_SESSION['~TC:Time'] = time() + $_SESSION['~TC:Min'];
}
function expiredTime(){//True if time has expired; false otherwise.
 return time() > $_SESSION['~TC:Time'];
}

 

Then I forgot to refresh the page, so it works great now!

Link to comment
https://forums.phpfreaks.com/topic/200316-is-my-logic-correct/#findComment-1051275
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.