Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How many visitors are currently online:) How can I do it in PHP?

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
How many visitors are currently online:) How can I do it in PHP? I want to know how much visitors are currently online on my web site. It is possible to do one script in PHP that show it in my website?
 
Here is my code, remember to add the db by yourself.
Hope it'd help you out

function online() {
$ip = getenv("REMOTE_ADDR");
$past = time()-900;
mysql_query(&quot;DELETE FROM session WHERE time < $past&quot;);
$result = mysql_query(&quot;SELECT time FROM session WHERE host_addr='$ip'&quot;);
$ctime = time();
if ($row = mysql_fetch_array($result)) {
mysql_query(&quot;UPDATE session SET username='time='$ctime', host_addr='$ip' WHERE host_addr='$ip'&quot;);
} else {
mysql_query(&quot;INSERT INTO session (time, host_addr) VALUES ('$ctime', '$ip')&quot;);
}

$result = mysql_query(&quot;SELECT host_addr FROM session&quot;);
$who_online_num = mysql_num_rows($result);
echo = &quot;<font size='1' face='verdana' color='#000000'>( $who_online Currently Online )</font>&quot;;
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top