The problem is not with the code the problem is with your
website host. As I have told earlier to you in some thread free hosts does
not allow use of socket functions and those queries require use of socket functions.
There are two solution to this :
1) Either upgrade your website host to premium cuz most of premium host allows the use of socket function but not all premium host allows it so if you upgrade then be sure to inquire before upgrading.
2) Other solution is to fetch server data indirectly by api which is hosted on socket supported host, I uploaded a php file on my site which outputs the server info in JSON object form, here is how you can use it:
Where X.X.X.X is the server ip and 7777 is the port.
Note that api is designed in such a way that if server is not online then it outputs "0".
Here is how you will use on your website.
PHP код:
<?php
//example
$url = 'http://brozeus.tk/api.php?srv=X.X.X.X&port=7777';//replace ip and port here
$data = file_get_contents($url);
if($data == "0")//if server is offline
{
echo "Server OFFLINE";
}
else
{
$data = json_decode($data, true);//decoding data and converting to array
echo "Server ONLINE";
echo "Host Name :".$data["hostname"];
echo "Server gamemode : ".$data["gamemode"];
echo "Map Name :".$data["mapname"]
echo "Current Players : ".$data["players"];
echo "Max Players : ".$data["maxplayers"];
}
?>
The keys name in array are case sensitive so make sure you use things as
$data["players"],
not $data["Players"]
All letters in array key will be in lowercase.