Lamez Posted January 12, 2010 Share Posted January 12, 2010 I have been playing around with checking on users with stale sessions. I decided to give this method a try. When they login a time will be set, in a session, then it will be checked constantly to see if their session is still good. I try putting in 1 as the limit (1 minuet?), but I still get "still chewy". here is the function in question: <?php function timeCheck($limit){ if(!isset($_SESSION['~time']) && !isset($_SESSION['~limit'])){ $_SESSION['~time'] = time(); $_SESSION['~limit'] = time()+$limit; } if($_SESSION['~time'] == $_SESSION['~limit']){ return "expired"; }else{ return "still chewy"; } } ?> Link to comment https://forums.phpfreaks.com/topic/188155-does-this-seem-logical/ Share on other sites More sharing options...
oni-kun Posted January 12, 2010 Share Posted January 12, 2010 Are you putting session_start(); at the top of your page? Link to comment https://forums.phpfreaks.com/topic/188155-does-this-seem-logical/#findComment-993348 Share on other sites More sharing options...
Lamez Posted January 12, 2010 Author Share Posted January 12, 2010 Yes, it is being included. Link to comment https://forums.phpfreaks.com/topic/188155-does-this-seem-logical/#findComment-993349 Share on other sites More sharing options...
oni-kun Posted January 12, 2010 Share Posted January 12, 2010 Yes, it is being included. if(!isset($_SESSION['~time']) && !isset($_SESSION['~limit'])){ $_SESSION['~time'] = time(); This sets the time, and does not update it based on the current time. if($_SESSION['~time'] == $_SESSION['~limit']){ What if ~time is over ~limit? You're not checking if it's greater than. Link to comment https://forums.phpfreaks.com/topic/188155-does-this-seem-logical/#findComment-993350 Share on other sites More sharing options...
Lamez Posted January 12, 2010 Author Share Posted January 12, 2010 Thanks for the help. That does make a lot of sense. Here is my new code: <?php function timeCheck($limit){ if(!isset($_SESSION['~limit'])){ $_SESSION['~limit'] = time()+$limit; } if(time() >= $_SESSION['~limit']){ return "expired"; }else{ return "still chewy"; } } ?> Now I am getting expired. I am setting the limit to 10, would that be 10 seconds or 10 minuets? The manual did not help much. Link to comment https://forums.phpfreaks.com/topic/188155-does-this-seem-logical/#findComment-993361 Share on other sites More sharing options...
oni-kun Posted January 12, 2010 Share Posted January 12, 2010 time(): Returns the current time measured in the number of seconds Link to comment https://forums.phpfreaks.com/topic/188155-does-this-seem-logical/#findComment-993363 Share on other sites More sharing options...
Lamez Posted January 12, 2010 Author Share Posted January 12, 2010 I see, so adding $limit *= 60; will turn it into minuets? Link to comment https://forums.phpfreaks.com/topic/188155-does-this-seem-logical/#findComment-993365 Share on other sites More sharing options...
oni-kun Posted January 12, 2010 Share Posted January 12, 2010 I see, so adding $limit *= 60; will turn it into minuets? Well yes, but you may as well just place: for ease. time()+($limit*60); Link to comment https://forums.phpfreaks.com/topic/188155-does-this-seem-logical/#findComment-993367 Share on other sites More sharing options...
Lamez Posted January 12, 2010 Author Share Posted January 12, 2010 I gotcha, save that RAM. So my final code works: <?php function timeCheck($limit){ if(!isset($_SESSION['~limit'])){ $_SESSION['~limit'] = time()+($limit*60); } if(time() >= $_SESSION['~limit']){ unset($_SESSION['~limit']); return "expired"; }else{ return "still chewy"; } } ?> Link to comment https://forums.phpfreaks.com/topic/188155-does-this-seem-logical/#findComment-993372 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.