Jump to content

Is my Logic Correct?


Lamez

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

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.