04.04.2015, 10:41
We use javascript and php simultaneously for that.
****** the term "ajax and php".
I prefer passing information in form form of json object, so here is a short example of how to do it :
First lets create the php file to get server info which outputs it in form of json.
Now to get info from php file into javascript we use ajax( note that you need jquery for it)
****** the term "ajax and php".
I prefer passing information in form form of json object, so here is a short example of how to do it :
First lets create the php file to get server info which outputs it in form of json.
PHP код:
//get_info.php
<?php
require("SampQueryAPI.php");
$query = new SampQueryAPI('127.0.0.1', '7777');//change ip and port here
if(!$query->isOnline())
{
echo "Server Offline";
exit();
}
$info = $query->getInfo();
echo json_encode($info);
?>
PHP код:
//javascript
$.ajax({
url: "get_info.php"
}).done(function(data)
{
var info = JSON.parse(data);
//now use info.players , info.maxplayers , info.hostname.... etc
alert("Game mode of server is : "+info.gamemode);
}