Jump to content

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

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.