I have the following code to get the number of online visitors and members:
session_save_path($_SERVER['DOCUMENT_ROOT'] . '/sessions/' . (isset($_COOKIE['uid']) ? "members/" : "guests/"));
if(isset($_COOKIE['uid'])){
session_id($_COOKIE['uid']);
}
session_start();
define("MAX_IDLE_TIME", 15);
$online_guests = 0;
$directory = opendir($_SERVER['DOCUMENT_ROOT'] . '/sessions/guests/');
while(false !== ($file = readdir($directory))){
$online_guests++;
}
$online_guests -= 2;
$online_members = array();
$directory = opendir($_SERVER['DOCUMENT_ROOT'] . '/sessions/members/');
while(false !== ($file = readdir($directory))){
if($file != '.' && $file != '..'){
$online_members[] = intval(substr($file,5));
}
}
I tested the code from my wamp server and it worked, but when I uploaded the code to my host it gives me the following error:
Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/csabi/public_html/index.php:9) in /home/csabi/public_html/track-online-users.php on line 6