Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
Olá pessoal estou trabalhando com uma api e faço a conexão com ela com esse codigo
<?php
//ini_set("display_errors", 1);
//ini_set("track_errors", 1);
//ini_set("html_errors", 1);
//error_reporting(E_ALL);
//The following script is tested only with servers running on Minecraft 1.7.
$SERVER_IP = $row_Recordset1['add_ip']; //Insert the IP of the server you want to query.
$SERVER_PORT = $row_Recordset1['add_porta']; //Insert the PORT of the server you want to ping. Needed to get the favicon, motd, players online and players max. etc
$QUERY_PORT = $row_Recordset1['add_porta']; //Port of query.port="" in your server.properties. Needed for the playerlist! Can be the same like the port or different. Query must be enabled in your server.properties file!
$HEADS = "3D"; //"normal" / "3D"
$show_max = "unlimited"; // how much playerheads should we display? "unlimited" / "10" / "53"/ ...
$SHOW_FAVICON = "on"; //"off" / "on"
$TITLE = "Test";
$TITLE_BLOCK_ONE = "General Information";
$TITLE_BLOCK_TWO = "Players";
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
$ping = json_decode(file_get_contents('[http://mcapi.sweetcode.de/api/v2/?info&ip=](http://mcapi.sweetcode.de/api/v2/?info&ip=)' . $SERVER_IP . '&' . $SERVER_PORT . ''), true);
$query = json_decode(file_get_contents('[http://mcapi.sweetcode.de/api/v2/?query&ip](http://mcapi.sweetcode.de/api/v2/?query&ip)' . $SERVER_IP . '&' . $QUERY_PORT . ''), true);
//Put the collected player information into an array for later use.
if(empty($ping['error'])) {
$version = $ping['version'];
$online = $ping['player']['online'];
$max = $ping['player']['max'];
$motd = $ping['motd'];
$favicon = $ping['favicon'];
}
if(empty($query['error'])) {
$playerlist = $query['Playerlist'];
}
?>
Depois uso esse codigo para exibir a informação que eu quero:
<?php echo "".$online." / ".$max."" ; ?>
Isso exibe no caso quantas pessoas estão online em um servidor mas caso o servidor estiver offiline a api não retorna nada, como eu coloco uma mensagem por exemplo "indisponivel" se a api não retornar nada
Carregando comentários...