• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

(PHP) Does anyone know a simple script for server status?

Guapoke

Member
Joined
Nov 21, 2008
Messages
259
Reaction score
5
I use sqlite and acc manager. I just want to make a website for news and server status.

I found this script for server status, but I can't make it work right, it's showing all info about the server togheter. I know basics in php so anything would help!

Code:
<?PHP // config
$server['host'] .= 'xxxx';
$server['port'] .= '7171';

// Verifing
$info = chr(6).chr(0).chr(255).chr(255).'info';
$sock = @fsockopen($server['host'],$server['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){
        print_r($XML);
        return $XML;
    }
    }
    else
    {
        $cnf_['players'] .= '0 / 0';
        $cnf_['uptime'] = '0';
        $cnf_['monsters'] = '0 h 0 m';
    }
// Showing
echo $cnf_['players'];
echo $cnf_['uptime'];
echo $cnf_['monsters'];

?>

I need it like, for example:
Server status: ONLINE
Players: 12/100
Monsters: xxx
Uptime: xxx

Thanks in advance.
 
Code:
<?PHP 
    //Config
    $server = array();
    $server['host'] = '127.0.0.1';
    $server['port'] = '7171';
   
    function xml2array ( $xmlObject, $out = array () )
    {
        foreach ( (array) $xmlObject as $index => $node )
        {
            $out[$index] = ( is_object ( $node ) ) ? xml2array ( $node ) : $node;
        }
        return $out;
    }
   
    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;
    }

    $xmlFile = getServerInformation($server['host'], $server['port']);  
    if($xmlFile) {
        $information = xml2array($xmlFile);
        print('Server online');
        print('Info: ' . $information['serverinfo']['@attributes']['ip'] . ' [' . $information['serverinfo']['@attributes']['client'] . ']' . '<br/>');
        print('Players: ' . $information['players']['@attributes']['online'] . ' (' . $information['players']['@attributes']['peak'] . ') / ' . $information['players']['@attributes']['max'] . '<br/>');
        print('Monsters: ' . $information['monsters']['@attributes']['total'] . '<br/>');
        print('Uptime (seconds): ' . $information['serverinfo']['@attributes']['uptime'] . '<br/>');
    }
    else
        print('Server offline / No response');
?>
 
Code:
<?PHP
    //Config
    $server = array();
    $server['host'] = '127.0.0.1';
    $server['port'] = '7171';
  
    function xml2array ( $xmlObject, $out = array () )
    {
        foreach ( (array) $xmlObject as $index => $node )
        {
            $out[$index] = ( is_object ( $node ) ) ? xml2array ( $node ) : $node;
        }
        return $out;
    }
  
    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;
    }

    $xmlFile = getServerInformation($server['host'], $server['port']); 
    if($xmlFile) {
        $information = xml2array($xmlFile);
        print('Server online');
        print('Info: ' . $information['serverinfo']['@attributes']['ip'] . ' [' . $information['serverinfo']['@attributes']['client'] . ']' . '<br/>');
        print('Players: ' . $information['players']['@attributes']['online'] . ' (' . $information['players']['@attributes']['peak'] . ') / ' . $information['players']['@attributes']['max'] . '<br/>');
        print('Monsters: ' . $information['monsters']['@attributes']['total'] . '<br/>');
        print('Uptime (seconds): ' . $information['serverinfo']['@attributes']['uptime'] . '<br/>');
    }
    else
        print('Server offline / No response');
?>

Works like a charm! Thank you sir :D
 
Back
Top