Users Online

Category: PHP
Reviewed by: armed rebel   
Reviewed on: Jul 05 2006
» Discuss this topic ( Posts)

Lastly, before you can call your users online script complete, you need a way to delete old records so you don't fill up 10,000 rows when you'll likely only need to use the newest 1%. This last part is an extremely simple 2 line script. If you know how and prefer it, you could set this as a CRON job, so wouldn't have to worry about it, but this way is just as simple and worry-free.

$maxtime = time() - 301;
mysql_query("DELETE FROM users_online WHERE last_active < '$maxtime'");

I find putting this under where you put the database updating script from Page 2 works fine. You can also increase the $maxtime to something more "safe", but it's not needed.

Conclusion

And this concludes my tutorial on displaying users online. If you have questions or comments on this or any tutorial of mine, feel free to email me using this form.