WTF PHP BAD!

Discussion in 'OT Technology' started by A Cow, Jul 15, 2007.

  1. A Cow

    A Cow OT Supporter

    Joined:
    Jul 7, 2005
    Messages:
    33,025
    Likes Received:
    97
    Location:
    Vancouver BC
    2 scripts.. *should* be the exact same thing.. one works one doesnt (aka all servers are "online" but 2 of them show offline under the first script.. why? )


    Code:
    <?
    
    //==========================================================
    // Tyson Clark
    // [email protected]
    // July 14th, 2007
    //==========================================================
    
    // ============ EDIT THESE TO YOUR SERVER ============== //
    $lip         = 'juliett.gamebitonline.com';    // Login Server Address
    $cip         = 'juliett.gamebitonline.com';    // Charator Server Address
    $mip         = 'juliett.gamebitonline.com';    // Map Server Address
    $uoip        = 'gametag.serveftp.com';        // Ultima Online Server Address
    $uoport    = '2593';                    // Ultima Online Port
    $lport    = '6900';                    //Login-Server Port
    $cport    = '6121';                    //Charator-Server Port
    $cporttwo    = '6122';                    // 2nd Charator Server Port
    $mport    = '5121';                    //Map-Server Port
    $mporttwo    = '5122';                    // 2nd Map Port
    $timeout    = 5;                        //Timeout ( in seconds )
    $debug    = 0;                        //Debug mode ( 1 on, 0 off )
    // ======================== STOP!!====================== //
    
    // ==== no touchie unless you know what your doing ==== //
    $errno     = 0;
    $errstr    = ''; 
    // ==== support will not be givin for these vars!! ==== //
    
    //Status check function
    function status_check( $ip, $port, $timeout, $debug, $errno, $errstr ) 
    {
    
        // Check server status
          $up = @fsockopen( $ip, $port, $errno, $errstr, $timeout );
    
        // Debugging
        if( $debug )
        {
            if( $errno )
            {
                echo "ERROR - $errstr<br / >\n";
            }
        }
        
        if( $up ) 
        {
            return "<font color='green'><b>Online</b></font><br>";
            // if you want to display an image use the following line.. i think?
            // return "<img border="0" src="online.gif" alt="Online" /><br>";
        }
        else 
        {
            return "<font color='red'><b>Offline</b></font><br>";
            // if you want to display an image use the following line.. i think?
            // return "<img border="0" src="offline.gif" alt="Offline" /><br>";
        }
            
        // close socket
          @fclose( $up );
    }
    
    
    function rostatus( $lip, $lport, $cip, $cport, $mip, $mport, $timeout, $debug) 
    {
        echo 'Login Server : '.status_check( $lip, $lport, $timeout, $debug, $errno, $errstr );
        echo '<b>Low Rate Server:</b><br> ';
        echo 'Char Server : '.status_check( $cip, $cport, $timeout, $debug, $errno, $errstr );
        echo 'Map Server : '.status_check( $mip, $mport, $timeout, $debug, $errno, $errstr );
        echo '<b>High Rate Server:</b><br> ';
        echo 'Char Server : '.status_check( $cip, $mporttwo, $timeout, $debug, $errno, $errstr );
        echo 'Map Server : '.status_check( $mip, $mporttwo, $timeout, $debug, $errno, $errstr );
    }
    
    function uostatus( $uoip, $uoport, $timeout, $debug) 
    {
        echo 'Ultima Shard : '.status_check( $uoip, $uoport, $timeout, $debug, $errno, $errstr );
    }
    
    ?>
        
    and the working one

    Code:
    <?
    
    //==========================================================
    // Tyson Clark
    // [email protected]
    // July 14th, 2007
    //==========================================================
    
    // ============ EDIT THESE TO YOUR SERVER ============== //
    $lip         = 'juliett.gamebitonline.com';    // Login Server Address
    $cip         = 'juliett.gamebitonline.com';    // Charator Server Address
    $mip         = 'juliett.gamebitonline.com';    // Map Server Address
    $uoip        = 'gametag.serveftp.com';        // Ultima Online Server Address
    $uoport    = '2593';                    // Ultima Online Port
    $lport    = '6900';                    //Login-Server Port
    $cport    = '6121';                    //Charator-Server Port
    $cporttwo    = '6122';                    // 2nd Charator Server Port
    $mport    = '5121';                    //Map-Server Port
    $mporttwo    = '5122';                    // 2nd Map Port
    $timeout    = 5;                        //Timeout ( in seconds )
    $debug    = 0;                        //Debug mode ( 1 on, 0 off )
    // ======================== STOP!!====================== //
    
    // ==== no touchie unless you know what your doing ==== //
    $errno     = 0;
    $errstr    = ''; 
    // ==== support will not be givin for these vars!! ==== //
    
    //Status check function
    function status_check( $ip, $port, $timeout, $debug, $errno, $errstr ) 
    {
    
        // Check server status
          $up = @fsockopen( $ip, $port, $errno, $errstr, $timeout );
    
        // Debugging
        if( $debug )
        {
            if( $errno )
            {
                echo "ERROR - $errstr<br / >\n";
            }
        }
        
        if( $up ) 
        {
            return "<font color='green'><b>Online</b></font><br>";
            // if you want to display an image use the following line.. i think?
            // return "<img border="0" src="online.gif" alt="Online" /><br>";
        }
        else 
        {
            return "<font color='red'><b>Offline</b></font><br>";
            // if you want to display an image use the following line.. i think?
            // return "<img border="0" src="offline.gif" alt="Offline" /><br>";
        }
            
        // close socket
          @fclose( $up );
    }
    
    
    function rostatus( $lip, $lport, $cip, $cport, $mip, $mport, $timeout, $debug) 
    {
        echo 'Login Server : '.status_check( $lip, $lport, $timeout, $debug, $errno, $errstr );
        echo '<b>Low Rate Server:</b><br> ';
        echo 'Char Server : '.status_check( $cip, $cport, $timeout, $debug, $errno, $errstr );
        echo 'Map Server : '.status_check( $mip, $mport, $timeout, $debug, $errno, $errstr );
        echo '<b>High Rate Server:</b><br> ';
        echo 'Char Server : '.status_check( $cip, 6122, $timeout, $debug, $errno, $errstr );
        echo 'Map Server : '.status_check( $mip, 5122, $timeout, $debug, $errno, $errstr );
    }
    
    function uostatus( $uoip, $uoport, $timeout, $debug) 
    {
        echo 'Ultima Shard : '.status_check( $uoip, $uoport, $timeout, $debug, $errno, $errstr );
    }
    
    ?>
        
    wtf?


    ( ps working one is posted at http://status.artofassassin.com/ dont have not working one up but im sure you can figure it out )
     
  2. whup

    whup I wish you had children and.. so that I could step

    Joined:
    Feb 12, 2007
    Messages:
    1,603
    Likes Received:
    0
    Get a file diff program like Araxis Merge.

    The difference is on lines 70 and 71, one of them has ports hardcoded.

    e.g. in the first example:

    Code:
        echo 'Char Server : '.status_check( $cip, $mporttwo, $timeout, $debug, $errno, $errstr );
        echo 'Map Server : '.status_check( $mip, $mporttwo, $timeout, $debug, $errno, $errstr );
    
    the working one has:

    Code:
     echo 'Char Server : '.status_check( $cip, 6122, $timeout, $debug, $errno, $errstr );
        echo 'Map Server : '.status_check( $mip, 5122, $timeout, $debug, $errno, $errstr );
    
     
  3. whup

    whup I wish you had children and.. so that I could step

    Joined:
    Feb 12, 2007
    Messages:
    1,603
    Likes Received:
    0
    So yeah by the looks the non-working one is using $mporttwo twice instead of $cporttwo, $mporttwo

    echo 'Char Server : '.status_check( $cip, $cporttwo, $timeout, $debug, $errno, $errstr );
    echo 'Map Server : '.status_check( $mip, $mporttwo, $timeout, $debug, $errno, $errstr );
     
  4. noon

    noon get high and teach me how to listen

    Joined:
    May 4, 2002
    Messages:
    3,384
    Likes Received:
    0
    Location:
    Lawrence, KS
    $mporttwo and $cporttwo are not defined in the rostatus function
     
  5. noon

    noon get high and teach me how to listen

    Joined:
    May 4, 2002
    Messages:
    3,384
    Likes Received:
    0
    Location:
    Lawrence, KS
    Code:
    <?
    
    //==========================================================
    // Tyson Clark
    // [email protected]
    // July 14th, 2007
    //==========================================================
    
    // ============ EDIT THESE TO YOUR SERVER ============== //
    $lip         = 'juliett.gamebitonline.com';    // Login Server Address
    $cip         = 'juliett.gamebitonline.com';    // Charator Server Address
    $mip         = 'juliett.gamebitonline.com';    // Map Server Address
    $uoip        = 'gametag.serveftp.com';        // Ultima Online Server Address
    $uoport    = '2593';                    // Ultima Online Port
    $lport    = '6900';                    //Login-Server Port
    $cport    = '6121';                    //Charator-Server Port
    $cporttwo    = '6122';                    // 2nd Charator Server Port
    $mport    = '5121';                    //Map-Server Port
    $mporttwo    = '5122';                    // 2nd Map Port
    $timeout    = 5;                        //Timeout ( in seconds )
    $debug    = 0;                        //Debug mode ( 1 on, 0 off )
    // ======================== STOP!!====================== //
    
    // ==== no touchie unless you know what your doing ==== //
    $errno     = 0;
    $errstr    = ''; 
    // ==== support will not be givin for these vars!! ==== //
    
    //Status check function
    function status_check( $ip, $port, $timeout, $debug, $errno, $errstr ) 
    {
    
        // Check server status
          $up = @fsockopen( $ip, $port, $errno, $errstr, $timeout );
    
        // Debugging
        if( $debug )
        {
            if( $errno )
            {
                echo "ERROR - $errstr<br / >\n";
            }
        }
        
        if( $up ) 
        {
            return "<font color='green'><b>Online</b></font><br>";
            // if you want to display an image use the following line.. i think?
            // return "<img border="0" src="online.gif" alt="Online" /><br>";
        }
        else 
        {
            return "<font color='red'><b>Offline</b></font><br>";
            // if you want to display an image use the following line.. i think?
            // return "<img border="0" src="offline.gif" alt="Offline" /><br>";
        }
            
        // close socket
          @fclose( $up );
    }
    
    
    function rostatus( $lip, $lport, $cip, $cport, $mip, $mport, $timeout, $debug, $cporttwo='6122', $mporttwo='5122') 
    {
        echo 'Login Server : '.status_check( $lip, $lport, $timeout, $debug, $errno, $errstr );
        echo '<b>Low Rate Server:</b><br> ';
        echo 'Char Server : '.status_check( $cip, $cport, $timeout, $debug, $errno, $errstr );
        echo 'Map Server : '.status_check( $mip, $mport, $timeout, $debug, $errno, $errstr );
        echo '<b>High Rate Server:</b><br> ';
        echo 'Char Server : '.status_check( $cip, $cporttwo, $timeout, $debug, $errno, $errstr );
        echo 'Map Server : '.status_check( $mip, $mporttwo, $timeout, $debug, $errno, $errstr );
    }
    
    function uostatus( $uoip, $uoport, $timeout, $debug) 
    {
        echo 'Ultima Shard : '.status_check( $uoip, $uoport, $timeout, $debug, $errno, $errstr );
    }
    
    ?>
     
  6. Peyomp

    Peyomp New Member

    Joined:
    Jan 11, 2002
    Messages:
    14,017
    Likes Received:
    0
    man diff
     
  7. A Cow

    A Cow OT Supporter

    Joined:
    Jul 7, 2005
    Messages:
    33,025
    Likes Received:
    97
    Location:
    Vancouver BC
    you all are a hero.

    P.S. i knew the files where diffrent.. i was trying to figure out why oen worked and one didnt.. not that they whrere diffrent
     
  8. Peyomp

    Peyomp New Member

    Joined:
    Jan 11, 2002
    Messages:
    14,017
    Likes Received:
    0
    If you diff'd them, you would see the difference... which would tell you why one works and one doesn't.
     

Share This Page