Why online users script doesn't show proper user count?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tutusaint
    New Member
    • Sep 2010
    • 18

    Why online users script doesn't show proper user count?

    I have a user count script thats well on my local host.
    I uploaded it into my webserver and it always shows 1 user online and even when i login from diferent ip addresses.
    The codes of my script is below.
    Please help
    Code:
    $server         	= "localhost";  		
    $db_user        	= "root"; 		   
    $db_pass        	= "root";                                   
    $database               ="test"                                      
    
    $timeoutseconds 	= 200;	
    
    $timestamp=time();                                                                                            
    $timeout=$timestamp-$timeoutseconds;  
    //$test=getenv("REMOTE_ADDR")
    mysql_connect($server, $db_user, $db_pass) or die ("Useronline Database CONNECT Error");                                                                   
    mysql_db_query($database, "INSERT INTO useronline VALUES ('$timestamp','$REMOTE_ADDR','$PHP_SELF')") or die("Useronline Database INSERT Error"); 
    mysql_db_query($database, "DELETE FROM useronline WHERE timestamp<$timeout") or die("Useronline Database DELETE Error");
    $result=mysql_db_query($database, "SELECT DISTINCT ip FROM useronline WHERE file='$PHP_SELF'") or die("Useronline Database SELECT Error");
    $user  =mysql_num_rows($result);                                                                              
    mysql_close();                                                                                                
    if ($user==1) {echo"<font size=1>$user Star(s) curently online.</font>";} else {echo"<font size=1> $user Star(s) curently online.";}
    ?>
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    #2
    If you examine the database after visiting the page, do you see multiple entries?

    Comment

    • tutusaint
      New Member
      • Sep 2010
      • 18

      #3
      It captures the timestamp only.
      The IP (IP address) and file is not captured.

      Comment

      • Markus
        Recognized Expert Expert
        • Jun 2007
        • 6092

        #4
        $REMOTE_ADDR? Do you mean $_SERVER['REMOTE_ADDR']? The same goes for $PHP_SELF. I do hope you're not using register globals. Also, are you seeing multiple entries in your database, if you have multiple visitors?

        Comment

        Working...