hi im trying to get the users that are online on my site and their IP address (so i can know how many Guests there are online).
this is the Script i use
if (getenv(HTTP_X_FORWARDED_FOR)){
$ip=getenv(HTTP_X_FORWARDED_FOR);
}
else {
$ip=getenv(REMOTE_ADDR);
}
$query="SELECT user FROM mundo_online WHERE user='$user' AND ip_address='$ip'";
$online->query($query);
$time=time();
IF($online->num_rows()==0)
{
$query = "INSERT INTO mundo_online (user, time, ip_address) VALUES ('$user','$time','$ip')";
$online->query($query);
}
ELSE
{
$query = "UPDATE mundo_online SET time='$time' WHERE user='$user' AND ip_address='$ip' ";
$online->query($query);
}
$query = "DELETE FROM mundo_online WHERE time <= ($time - 60*10) ";
$online->query($query);
That script i loaded everytime a user loads a page. Im not sure i i can get the REAL IP with that sccript or to use
if (getenv(HTTP_CLIENT_IP)){
$ip=getenv(HTTP_CLIENT_IP);
}
else {
$ip=getenv(REMOTE_ADDR);
}
And i have another big problem.
Some users dont get their IP into the TABLE. So it does 2 inserts, one for the one with the IP and one without the IP, so i looks like there where 2 users online.
Is something wrong on the code or something ? or what is it ?
Thanks !