daled Posted August 15, 2007 Share Posted August 15, 2007 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 More sharing options...
trq Posted August 15, 2007 Share Posted August 15, 2007 You also need to insert a timestamp into the db. On each request this timestamp needs to be updated. Then, you simply run a cron job every ten minutes or so that removes entries older then 10 mins or so. Link to comment https://forums.phpfreaks.com/topic/65058-solved-active-users/#findComment-324666 Share on other sites More sharing options...
daled Posted August 15, 2007 Author Share Posted August 15, 2007 alright, i can try that. what's a cron job? Link to comment https://forums.phpfreaks.com/topic/65058-solved-active-users/#findComment-324678 Share on other sites More sharing options...
chocopi Posted August 15, 2007 Share Posted August 15, 2007 http://en.wikipedia.org/wiki/Crontab Link to comment https://forums.phpfreaks.com/topic/65058-solved-active-users/#findComment-324681 Share on other sites More sharing options...
NArc0t1c Posted August 15, 2007 Share Posted August 15, 2007 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 More sharing options...
daled Posted August 15, 2007 Author Share Posted August 15, 2007 http://en.wikipedia.org/wiki/Crontab so then how can i make one? Link to comment https://forums.phpfreaks.com/topic/65058-solved-active-users/#findComment-324700 Share on other sites More sharing options...
trq Posted August 15, 2007 Share Posted August 15, 2007 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 More sharing options...
daled Posted August 15, 2007 Author Share Posted August 15, 2007 i'm sorry that i'm such a mediocre coder, but what are you talking about? right now I don't have a host, i'm on a testing server. is that a "shell"? and then what would the 'appropriate entry' be? Link to comment https://forums.phpfreaks.com/topic/65058-solved-active-users/#findComment-324708 Share on other sites More sharing options...
trq Posted August 15, 2007 Share Posted August 15, 2007 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 More sharing options...
daled Posted August 15, 2007 Author Share Posted August 15, 2007 i'm on windows with apache. :edit: read the last part, god, what hopelessness. is there anything you can point me to? Link to comment https://forums.phpfreaks.com/topic/65058-solved-active-users/#findComment-324715 Share on other sites More sharing options...
trq Posted August 15, 2007 Share Posted August 15, 2007 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 More sharing options...
daled Posted August 15, 2007 Author Share Posted August 15, 2007 i found a way by running the script manually in firefox. it's good enough for me right now. the hosting i'll probably use supports cron so that'll be fine. something else i found out is using the scheduled task thing. Link to comment https://forums.phpfreaks.com/topic/65058-solved-active-users/#findComment-324772 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.