/PHP-Minecraft-Server-Status-Query

[FR] Minecraft serveur status query avec slots et joueurs connectés sans plugins et "enable-query"

Primary LanguagePHP

Minecraft Server Status Query

Minecraft server status query with slots and online players query without plugins and enable-query working with nearly every minecraft version including 1.8, 1.7.10 etc.
Download all files, view the example.php on your webserver and feel free to use it.
Twitter: https://twitter.com/Spravil <-- Follow if you like my work and want to stay up to date :)

Tutorial

Firstly, you have to include in your php file the status.class.php and call the class.

include_once 'MinecraftServerStatus/status.class.php'; //include the class
$status = new MinecraftServerStatus(); // call the class

Then you call the getStatus() function. You have to replace the domain 'pvp24.com' with the ip or domain of your server.

$response = $status->getStatus('pvp24.com'); // call the function 

Also if your server dont have the default port (25565) you can add it as getStatus(ip, version, port).

$response = $status->getStatus('pvp24.com', '1.7.10',  25565); // when you dont have the default port 

When you server runs an older version then 1.7.* you must specify the version.

$response = $status->getStatus('pvp24.com', '1.6.*'); // when you server is older then 1.7.*

After that you only have to check the response.

if(!$response) {
    echo"The Server is offline!";
} else {
	echo"<img width=\"64\" height=\"64\" src=\"".$response['favicon']."\" /> <br>
    The Server ".$response['hostname']." is running on ".$response['version']." and is online,
    currently are ".$response['players']." players online
    of a maximum of ".$response['maxplayers'].". The motd of the server is '".$response['motd']."'.
    The server has a ping of ".$response['ping']." milliseconds.";
}

If the server is offline it returns false else it returns an array which contains variables.

Variables

The table contains the aviable variables the response can contain.
The default content of each variable is false.

Array Index Description
'hostname'
Exact server address in 127.0.0.1 format
'version'
The server version
(for example: 1.8)
'protocol'
The server protocol
(for example: 4)
'players'
Amount of players who are currently online
'maxplayers'
Number of the slots of the server
'motd'
The message of the day of the server
'motd_raw'
The raw version of the motd of the server
(contains color codes etc.)
'favicon'
The favicon of the server in a base64 string
(Can be displayed with the html img tag by setting the string as src)
'ping'
The time the server needs to respond in ms