Jump to content

[SOLVED] active users


daled

Recommended Posts

how can I use PHP to tell if a user is active or not.  i'm using mysql to change 'status' field to 'logged in' when a user becomes active. but the only way to change the field to 'logged out' is by actually logging out, it doesn't change if you close the window.  Same when a guest visits the site, i can make the field 'logged in', but can't change it to 'logged out'.  How can i do this with PHP?

 

Link to comment
https://forums.phpfreaks.com/topic/65058-solved-active-users/
Share on other sites

Try inserting an row in the table that hold the active coloum.

And then add a update query to every page(include a single file to do it) to update it to current time.

 

And then you could use this to see if they are active:

<?php
$Limit = 3600; //A hour;
$LastTime = mysql_query("SELECT last_time FROM table WHERE user='$user');
$Fetch = mysql_fetch_row($LastTime);
if ($Fetch['last_time'] >= $Limit){
echo 'User is not active.';
} else {
echo 'User Is active.'; }
?>

Link to comment
https://forums.phpfreaks.com/topic/65058-solved-active-users/#findComment-324688
Share on other sites

so then how can i make one?

 

Firstly you need to find out if you host supports it. Then, if they do, they may either provide some sort of control panel to set one up, or, better still, if you have shell access you can do it yourself.  Simply run...

 

crontab -e

 

and add the appropriate entry.

Link to comment
https://forums.phpfreaks.com/topic/65058-solved-active-users/#findComment-324701
Share on other sites

i'm on a testing server

 

Is the testing server Linux? The shell is a command line interface to Linux.

 

and then what would the 'appropriate entry' be?

 

To run a job every 10 minutes that executes a php script.

 

*/10 * * * * /path/to/php/script.php

 

If your using windows.... I'm sorry, but you'd need to find another method (I'm not sure).

Link to comment
https://forums.phpfreaks.com/topic/65058-solved-active-users/#findComment-324714
Share on other sites

The only way I can think of to do it in windows would be to run the query that removes older entries on each request as well. I don't think you can run scripts at timed intervals with windows.

 

Of course this means that your if you get to the point where there is no active users, your script would still display the last active user as being logged in. this shouldn't matter though because there will be nobody around to see it.

Link to comment
https://forums.phpfreaks.com/topic/65058-solved-active-users/#findComment-324721
Share on other sites

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.