[HELP] Server online stats
Hello everyone,
Does anybody know how can I display a list of online players live in the browser, with PHP or any other language.
It's not for my own server, it's for any mta server that is online, so I just change the IP and PORT, and it displays the data from another server.
Something like the game-state.com displays: https://www.game-state.com/164.132.203.95:22003/
I tried something like this, and it does work, but sometimes it just doesn't display anything, I don't know why. Most of the time it does work, but when it doesn't, game-state still works.
PHP Code:
<?php
$page = $_SERVER['PHP_SELF'];
$sec = "10";
?>
<html>
<head>
<meta http-equiv="refresh" content="<?php echo $sec?>;URL='<?php echo $page?>'">
</head>
<body>
<?php
$ip = '164.132.203.95';
$port = '22003';
$socket = fsockopen ( 'udp://' . $ip, $port+123, $errno, $errstr );
socket_set_timeout ( $socket, 1, 0 );
if ( $socket ) {
fwrite ( $socket, 's' );
$data = fread ( $socket, 16384 );
fclose ( $socket );
echo $data;
}
?>
</body>
</html>
I can't use game-state, because I need the data, so I can do something else with it later, and I know it's not the best option to refresh the whole page every 10 seconds, but for what I need, it's ok.
If anyone has any solution, please let me know, and thanks in advance!
Re: [HELP] Server online stats
Re: [HELP] Server online stats
Not exactly what I need, that's for displaying whether the server is online or not. I need to display the player list on the server, but thank you!
Re: [HELP] Server online stats
You can use javascript, for example,
PHP Code:
<script type="text/javascript">
function showPlayers0() {
if(document.getElementById("players0").style.display == "none") {
if ($("#players0").attr("shown") == "false") {
document.getElementById("players0").style.display = "block";
$("#players0").attr("shown", "true");
$.get( "js/ajax.php?t=players", function( data ) {
pData = JSON.parse(data)[0];
document.getElementById("playersSpinner").style.display = "none";
for (var i in pData["players"]) {
$("#players0").append("<li><a href=\"?pg=viewprofile&login=" + pData["players"][i]["acc"] + "\">" + pData["players"][i]["nick"] + "</a></li>");
}
});
} else {
document.getElementById("players0").style.display = "block";
}
} else {
document.getElementById("players0").style.display = "none";
}
}</script>
If u know php then it ll be easy for u.