ghgarcia Posted December 6, 2006 Share Posted December 6, 2006 I'm looking for a script to determine who is currently accessing my site. Any help would be greatly appreciated.ThanksGeorge Link to comment https://forums.phpfreaks.com/topic/29708-script-for-who-is-online-at-my-site/ Share on other sites More sharing options...
The Little Guy Posted December 6, 2006 Share Posted December 6, 2006 just the number of users currently on?Like this: http://d-top.org (top left) Link to comment https://forums.phpfreaks.com/topic/29708-script-for-who-is-online-at-my-site/#findComment-136363 Share on other sites More sharing options...
ghgarcia Posted December 7, 2006 Author Share Posted December 7, 2006 Yes that would work.Thanks Link to comment https://forums.phpfreaks.com/topic/29708-script-for-who-is-online-at-my-site/#findComment-136728 Share on other sites More sharing options...
Bushido718 Posted December 7, 2006 Share Posted December 7, 2006 Well, you'll need a database named 'online' with 2 rows (fields 'ip' (TEXT), and 'timestamp' (INT)).Note this may not be the best way to do this but this is how i would do it.[code]<?php//connect to you databasemysql_connect("localhost", "user", "pass");mysql_select_db("your_db");//get the users ip$user_ip = $_SERVER['REMOTE_ADDR'];//get the current time$time = time();//add 300 seconds (5 mins) to the time variable$stamp = $time + 300;//query for previous entries frm this user$query = mysql_query("SELECT * FROM 'online' WHERE 'timestamp' > '$time' AND 'ip' = '$user_ip'");if(!mysql_num_rows($query)){ //if no entries are found, add one mysql_query("INSERT INTO 'online' ('ip', 'timestamp') VALUES('$user_ip', '$stamp')");}else{ //if one is found update the time stamp mysql_query("UPDATE 'online' SET 'timestamp' = '$stamp' WHERE 'ip' = '$user_ip'");}//delete idle entriesmysql_query("DELETE FROM 'online' WHERE 'timestamp' < '$time'");//pull out all entries$query = mysql_query("SELECT * FROM 'online'");//get the number of entres$num_users = mysql_num_rows($query);//display itecho $num_users;?>[/code]that should work, will be accurate within 5 mins. Link to comment https://forums.phpfreaks.com/topic/29708-script-for-who-is-online-at-my-site/#findComment-136732 Share on other sites More sharing options...
ghgarcia Posted December 7, 2006 Author Share Posted December 7, 2006 Thanks that did the trick. I changed it a little to fit my site but it works great.Thanks again,George Link to comment https://forums.phpfreaks.com/topic/29708-script-for-who-is-online-at-my-site/#findComment-137159 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.