Jump to content

Is it my math? I bet it is my math. It is always my math.


Recommended Posts

Back, again,


So I have this function to check users if they are inactive for a certain length of time, then it marks them as offline, and vise-versa (did I spell that right?).


The problem is it is marking everyone as offline! I checked the logic, and  the queries. It all checks out.

I do not grasp the complete concept of the time() function, other than it produces some sorta time stamp.


From my understanding, it is in seconds. So to get a 5 minuets ahead you would do:




Well any who, here is my function:

//Note: The echos are for debuggin' purposes
function checkStaleUsers($checkInt, $idleTime){
$time = time();
	$_SESSION['~serverTimeCheck'] = time()+($checkInt*60);
if(time() >= $_SESSION['~serverTimeCheck']){
	$q = mysql_query("SELECT * FROM ".TBL_PEOPLE." WHERE timestamp > '0' AND activated = '1' AND ban = '0'");
	$n = mysql_num_rows($q);
	if($n > 0){
		while($f = mysql_fetch_array($q)){
			if($f['timestamp'] <= $time+($idleTime*60) && $f['online'] == 1){
				mysql_query("UPDATE ".TBL_PEOPLE." SET online = '0' WHERE id = '".$f['id']."'");
				echo "SET OFFLINE FOR: ".$f['email']."<BR>";
			}else if($f['timestamp'] >= $time+($idleTime*60) && $f['online'] == 0){
				mysql_query("UDPATE ".TBL_PEOPLE." SET online = '1' WHERE id = '".$f['id']."'");
				echo "SET ONLINE FOR: ".$f['email']."<BR>";
				echo $f['online'];
				echo "<BR>";
				echo $f['email'];
				echo "<BR>";
				echo $f['timestamp'];
				echo "<BR>";
				echo $time;
				echo "<HR>";
checkStaleUsers(5, 10); //Check every five minuets for users that are idle for ten minuets or more.


-Thanks, again.

Link to comment
Share on other sites

I consider my self semi-advanced, drifting from the noob stage. I know more PHP than I do SQL, so if the code could be condense, I am all for it. Could you explain your query to me a little more? What is this timestamp + 300?, what is this now(), is it like time()?



Link to comment
Share on other sites

now() will insert a timestamp in to the field for literally, right now.  So when you insert the user as being "online", use now() to generate the timestamp.


What ignace's query does, is compares the timestamp field, plus 300 (60 seconds x 5 for 5 minutes) to the time now.  So if when they logged in, plus 5 minutes, is less than the time now - they're no longer logged in.


Hopefully that makes a bit more sense ! :D

Link to comment
Share on other sites

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.

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.