I found a script at the net but it have a small mistake. I tried 3 hours but i can`t get it work.
The problem is i believe at those lines
$get_ip = mysql_query("SELECT * FROM ".$db_table." WHERE vis_ip=".$vis_ip." LIMIT 1");
while ($row=mysql_fetch_object($get_ip))
It doesn`t get inside the while to execute the next lines
the whole script is that
<?php
// config variables
$tframe = 1000; // time frame (minutes) to count active users
// database connection details
$db_host = "localhost"; // hostname of your MySQL server. You most likely don't have to change this
$db_name = "**_fruits"; // database name
$db_user = "**_apples"; // database user
$db_pass = "**"; // database password
$db_table= "visits"; // table name
// Lets open up a connection to the database
$db = mysql_connect($db_host,$db_user,$db_pass);
mysql_select_db ($db_name) or die ("Cannot connect to database");
// On to the counter processing...
$vis_ip = ip2long($_SERVER['REMOTE_ADDR']);
$time = time();
$new_vis = 1;
// update database for returning visitor
$get_ip = mysql_query("SELECT * FROM ".$db_table." WHERE vis_ip=".$vis_ip." LIMIT 1");
while ($row=mysql_fetch_object($get_ip))
{
mysql_query("UPDATE ".$db_table." SET vis_time='$time' WHERE vis_ip='$vis_ip'")
or die (mysql_error());
$new_vis = 0;
}
// add to database for new visitor
if ($new_vis == 1)
{
mysql_query("INSERT INTO ".$db_table." (vis_ip, vis_time) VALUES ('$vis_ip','$time')")
or die (mysql_error());
}
// done processing the visit, now lets see how many total visitors are online
$tcheck = time() - (60 * $tframe);
$query = mysql_query("SELECT * FROM ".$db_table." WHERE vis_time > $tcheck");
$onlinenow = mysql_num_rows($query);
// show number of visitors on screen
if($onlinenow == 1)
{
echo"currently $onlinenow visitor online";
}
else
{
echo"currently $onlinenow visitors online";
}
?>