Jump to content

Does this seem Logical?


Lamez

Recommended Posts

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

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.

 

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.

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";
}
}
?>

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.