Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Jul 2011
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Need Quick Fix of old php user online script dunno php or how to fix?

    my error messages:

    Notice: Undefined variable: HTTP_X_FORWARDED_FOR in D:\Apache_Server\htdocs\Roleplay_Realm_Online3\Script_Files\How_Many_Online_Website\online.php on line 4

    Notice: Use of undefined constant REMOTE_ADDR - assumed 'REMOTE_ADDR' in


    my php code:

    <?php
    $log_file="online.txt";
    $min_online="1";
    if ($HTTP_X_FORWARDED_FOR == "") {
    $ip = getenv(REMOTE_ADDR);
    }
    else {
    $ip = getenv(HTTP_X_FORWARDED_FOR);
    }
    $day =date("d");
    $month =date("m");
    $year =date("Y");
    $date="$day-$month-$year";
    $ora = date("H");
    $minuti = date("i");
    $secondi = date("s");
    $time="$ora:$minuti:$secondi";
    $users_read = fopen("$log_file", "r");
    $users = fread($users_read, filesize("$log_file"));
    fclose($users_read);
    $to_write="$ip|$time|$date";
    if($users==0){
    $user_write = fopen("$log_file", "w");
    fputs($user_write , $to_write );
    fclose($user_write );
    }
    else{
    $users=explode("\n",$users);
    $user_da_tenere=array();
    while (list ($key, $val) = each ($users)) {
    $user_sing=explode("|",$val);
    if($date==$user_sing[2]){
    $h=explode(":",$user_sing[1]);
    if($ip!=$user_sing[0]){
    if(($h[0]==$ora)and(($minuti-$h[1])<=$min_online)){
    $user_da_tenere[]=$val;}
    if(($h[0]==($ora-1))and((($minuti+2)-$h[1])<=$min_online)){
    $user_da_tenere[]=$val;
    }
    }
    }
    }
    $user_da_tenere[]=$to_write;
    $user_write = fopen("$log_file", "w");
    fputs($user_write , "" );
    fclose($user_write );
    while (list ($k, $v) = each ($user_da_tenere)) {
    $new_file_log = fopen ("$log_file", "a");
    fwrite($new_file_log,"$v\n");
    fclose($new_file_log);
    }
    }
    $users_online_read = fopen("$log_file", "r");
    $users_online = fread($users_online_read, filesize("$log_file"));
    fclose($users_online_read);
    $users_online=explode("\n",$users_online);
    $n_u_online=count($users_online)-1;
    echo "<b>There Are Currently $n_u_online Users Browsing This Website</b>";
    echo"<meta http-equiv=\"Refresh\" content=\"60; URL=online.php\" >";
    ?>

  • #2
    Regular Coder Nile's Avatar
    Join Date
    Jun 2008
    Posts
    280
    Thanks
    2
    Thanked 46 Times in 46 Posts
    Assuming the only issues were the notices you reported.
    PHP Code:
    <?php
    $log_file   
    "online.txt";
    $min_online "1";
    if (
    $_SERVER['HTTP_X_FORWARDED_FOR'] == "") {
        
    $ip getenv($_SERVER['REMOTE_ADDR']);
    } else {
        
    $ip getenv($_SERVER['HTTP_X_FORWARDED_FOR']);
    }
    $day date("d");
    $month date("m");
    $year date("Y");
    $date "$day-$month-$year";
    $ora date("H");
    $minuti date("i");
    $secondi date("s");
    $time "$ora:$minuti:$secondi";
    $users_read fopen("$log_file""r");
    $users fread($users_readfilesize("$log_file"));
    fclose($users_read);
    $to_write "$ip|$time|$date";
    if (
    $users == 0) {
        
    $user_write fopen("$log_file""w");
        
    fputs($user_write$to_write);
        
    fclose($user_write);
    } else {
        
    $users explode("\n"$users);
        
    $user_da_tenere = array();
        while (list(
    $key$val) = each($users)) {
            
    $user_sing explode("|"$val);
            if (
    $date == $user_sing[2]) {
                
    $h explode(":"$user_sing[1]);
                if (
    $ip != $user_sing[0]) {
                    if ((
    $h[0] == $ora) and (($minuti $h[1]) <= $min_online)) {
                        
    $user_da_tenere[] = $val;
                    }
                    if ((
    $h[0] == ($ora 1)) and ((($minuti 2) - $h[1]) <= $min_online)) {
                        
    $user_da_tenere[] = $val;
                    }
                }
            }
        }
        
    $user_da_tenere[] = $to_write;
        
    $user_write fopen("$log_file""w");
        
    fputs($user_write"");
        
    fclose($user_write);
        while (list(
    $k$v) = each($user_da_tenere)) {
            
    $new_file_log fopen("$log_file""a");
            
    fwrite($new_file_log"$v\n");
            
    fclose($new_file_log);
        }
    }
    $users_online_read fopen("$log_file""r");
    $users_online fread($users_online_readfilesize("$log_file"));
    fclose($users_online_read);
    $users_online explode("\n"$users_online);
    $n_u_online count($users_online) - 1;
    echo 
    "<b>There Are Currently $n_u_online Users Browsing This Website</b>";
    echo 
    "<meta http-equiv=\"Refresh\" content=\"60; URL=online.php\" >";
    ?>

  • #3
    New to the CF scene
    Join Date
    Jul 2011
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    now i get this messege:

    Notice: Undefined index: HTTP_X_FORWARDED_FOR in D:\Apache_Server\htdocs\Roleplay_Realm_Online3\Script_Files\How_Many_Online_Website\online.php on line 4

    Notice: Undefined offset: 2 in D:\Apache_Server\htdocs\Roleplay_Realm_Online3\Script_Files\How_Many_Online_Website\online.php on line 30
    There Are Currently 1 Users Browsing This Website


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •