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
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
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

 

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
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

 

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.