[PHP] Visitors online.

Socius Decennalis
Decennium
Joined
Aug 15, 2008
Messages
489
Reaction score
43
Hello.

I followed a tutorial about how to make a visitors online page. I got it fully working, but I would like to make few changes to it, but I am not sure how to do them, so I hope someone of you could help me.

So, the script looks right now like this:
Code:
<?php

session_start();

$session_path = session_save_path();
$visitors=0;

$handle = opendir(session_save_path());

while (($file = readdir($handle)) != FALSE)
{
 if ($file!="."&&$file!="..")
 {
  
    if(ereg("^sess",$file))
  		$visitors++;
 }
}

echo "There are $visitors visitors online.";

?>

So it just gets the count of visitors viewing the website, but I would like to get it to get visitors those are in a server. So like from port 3306.
 
In a schema, add a table called 'visitors', when someone joins with a fresh session, add a row and get their unique id and store it in their session as some variable so you can be sure not to add another row for them. Also use NOW() to insert the time they first visited, and each time they load another page update the last-visited time in their table, then just do a select with a date diff to get a list of users active in the past X minutes.
 
Back