1. 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 $socket1); 
              
            if ( 
    $socket ) { 
                
    fwrite $socket's' ); 
                
    $data fread $socket16384 ); 
                
    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!

  2. Re: [HELP] Server online stats 06-09-2019, 13:53 • #2
    https://forum.mtasa.com/topic/31769-...us-php-script/
    Yeah I took a xan, I hope u understand

  3. Re: [HELP] Server online stats 06-09-2019, 14:03 • #3
    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!

  4. Re: [HELP] Server online stats 06-09-2019, 14:39 • #4
    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.
    Yeah I took a xan, I hope u understand
    1 Like

1 Users reading this thread (0 Members and 1 Guests)