Lamez Posted April 30, 2010 Share Posted April 30, 2010 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 More sharing options...
Lamez Posted April 30, 2010 Author Share Posted April 30, 2010 Okay, so I printed out the timestamps. I am doing something wrong: Here is time(): 1272660826 Here is $_SESSION['~TC:Time']: 1.6926659444736E+30 I got that large number after I refreshed the page a couple times. Any suggestions? Link to comment https://forums.phpfreaks.com/topic/200316-is-my-logic-correct/#findComment-1051265 Share on other sites More sharing options...
Lamez Posted April 30, 2010 Author Share Posted April 30, 2010 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.