Jump to content

whos online?


vijdev

Recommended Posts

There are a ton of 'who is online' scripts posted all over the internet.

 

You use a database table. Anytime someone navigates to a page you insert/update a record for them in the table. If that person is logged in, as determined by your login code, you enter their username. If that person is not logged in, you enter them as a non-logged in guest. You can keep track of each guest by using the same kind of session that you are using for your logged in members, but save a value indicating the 'guest' status.

 

To display the values you simply get a list of the logged in usernames and count the 'guest' records from the table.

Link to comment
https://forums.phpfreaks.com/topic/213973-whos-online/#findComment-1113941
Share on other sites

$ip = $_SERVER['REMOTE_ADDR'];

if($ip){
$res = mysql_query("select from table where ip='{$ip}' limit 1"); //ip is varchar 255

if($res){
$num = mysql_num_rows($res);

if($num == 0){
mysql_query("insert into table set ip='{$ip}' ");
}//end if num
}//end if res
}//end if ip

 

Run cron to delete ips every 5 mins or so, then just count the rows

 

..and they lived happily ever after..

The end

Link to comment
https://forums.phpfreaks.com/topic/213973-whos-online/#findComment-1113987
Share on other sites

  Quote

$ip = $_SERVER['REMOTE_ADDR'];

if($ip){
$res = mysql_query("select from table where ip='{$ip}' limit 1"); //ip is varchar 255

if($res){
$num = mysql_num_rows($res);

if($num == 0){
mysql_query("insert into table set ip='{$ip}' ");
}//end if num
}//end if res
}//end if ip

 

Run cron to delete ips every 5 mins or so, then just count the rows

 

..and they lived happily ever after..

The end

 

or instead of cron you can store a timestamp and match that against the current time, deleting any entries older than 5mins or whatever.

Link to comment
https://forums.phpfreaks.com/topic/213973-whos-online/#findComment-1114011
Share on other sites

  Quote

  Quote

$ip = $_SERVER['REMOTE_ADDR'];

if($ip){
$res = mysql_query("select from table where ip='{$ip}' limit 1"); //ip is varchar 255

if($res){
$num = mysql_num_rows($res);

if($num == 0){
mysql_query("insert into table set ip='{$ip}' ");
}//end if num
}//end if res
}//end if ip

 

Run cron to delete ips every 5 mins or so, then just count the rows

 

..and they lived happily ever after..

The end

 

or instead of cron you can store a timestamp and match that against the current time, deleting any entries older than 5mins or whatever.

 

You still need cron for that too. I wouldnt recommend deleting rows every time a page is called, thats bad and expensive

Link to comment
https://forums.phpfreaks.com/topic/213973-whos-online/#findComment-1114927
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.