• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

PHP Serverstatus not updating

Webtimize

Pro Grammer
Joined
Oct 3, 2011
Messages
491
Solutions
10
Reaction score
182
Location
Hell
Hello everyone,

I'm currently working with a serverstatus script found on OTLand, but it's not working propperly.Even while the server is online, it keeps saying that it isn't.

The fun part is, when I restart the server and refresh the page, it'll say that the server is online.When pressing F5 once again, it comes up with server offline.

Config settings;
PHP:
$server = array();
$server['host'] = '31.xxx.xxx.xx';
$server['port'] = '7171';

general.class.php;
PHP:
class general {

    public function xml2array( $xmlObject, $out = array ()){
        foreach ( (array) $xmlObject as $index => $node ){
            $out[$index] = ( is_object ( $node ) ) ? self::xml2array ( $node ) : $node;
        }
        return $out;
    }
  
    public function getServerInformation($host, $port){
        $info = chr(6).chr(0).chr(255).chr(255).'info';
        $sock = @fsockopen($host, $port, $errno, $errstr, 1);
        if ($sock){
            fwrite($sock, $info);
            $data = '';
            while (!feof($sock))
                $data .= fgets($sock, 4096);
              
            fclose($sock);
            $XML = @simplexml_load_string($data);
            if($XML)
                return $XML;
        }
        return false;
    }

}

serverStatus.php;
PHP:
<?php
    $xmlFile = $general->getServerInformation($server['host'], $server['port']); 
    if($xmlFile) {
        $information = $general->xml2array($xmlFile);
      
        if( $information['players']['@attributes']['online'] < 1) {
            echo '<span style="color: green;">There are no players online right now.</span>';
        }
        else {
            echo '<span style="color: green;">There are currently '. $information['players']['@attributes']['online'] .' players online.</span>';
        }      
    }
    else {
        echo '<span style="color: orange;">The server is offline.</span>';
    }
?>

I hope someone can help me, thanks in advance.
 
Last edited:
Back
Top