Thread: [Solved] Get playerlist with php
View Single Post
Airkish
AlliedModders Donor
Join Date: Apr 2016
Location: Lithuania
Old 12-22-2017 , 09:37   Re: Get playerlist with php
Reply With Quote #8

Here you can have it (make sure to change localhost to your server IP):

PHP Code:
<?php
    
require __DIR__ '/../SourceQuery/bootstrap.php';

    use 
xPaw\SourceQuery\SourceQuery;
    
    
    
// Edit this ->
    
define'SQ_SERVER_ADDR''localhost' );
    
define'SQ_SERVER_PORT'27015 );
    
define'SQ_TIMEOUT',     );
    
define'SQ_ENGINE',      SourceQuery::SOURCE );
    
// Edit this <-
    
    
$Query = new SourceQuery( );
    
    try
    {
        
$Query->ConnectSQ_SERVER_ADDRSQ_SERVER_PORTSQ_TIMEOUTSQ_ENGINE );

        
$serverInfo $Query->GetInfo();
        
$playerData $Query->GetPlayers();

    }
    catch( 
Exception $e )
    {
        echo 
$e->getMessage( );
    }
    finally
    {
        
$Query->Disconnect( );
    }
?>

<!DOCTYPE html>
<html>
<head>
    <title><?php echo $serverInfo['HostName'] . "players"?></title>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
    <style>
        body {
            background: #111111;
            background-image: -webkit-repeating-radial-gradient(center center, rgba(43, 41, 61,.2), rgba(43, 41, 61,.2) 2px, transparent 1px, transparent 100%);
            background-size: 7px 7px;
            color: #fff;
            margin-top: 70px;
        }
        tbody {
            color: #7A7A7A;
        }
        table {
            background: #fff;
        }
        thead tr {
            background: #EA6153;
        }
        td:nth-child(1), th:nth-child(1) {
            width: 6%;
        }
        tr:nth-child(even) {
            background: #e6e6e6;
        }
        .server {
            text-align: center;
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="row">
            <div class="col-md-8 col-md-offset-2">
                <div class="server">
                    <h3><?php echo $serverInfo['HostName']; ?></h3>
                    <h4><?php echo $serverInfo['Map'] . " [ " $serverInfo['Players'] . " / " $serverInfo['MaxPlayers'] . " ]"?></h4>
                </div>
                <table class="table">
                    <thead>
                        <tr>
                            <th>Rank</th>
                            <th>Name</th>
                            <th>Score</th>
                            <th>Time Played</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php for($i 0$i $serverInfo['Players']; $i++) { ?>
                        <tr>
                            <td><?php echo $i+1?></td>
                            <td><?php echo $playerData[$i]['Name']; ?></td>
                            <td><?php echo $playerData[$i]['Frags']; ?></td>
                            <td><?php echo $playerData[$i]['TimeF'];; ?></td>
                        </tr>
                        <?php ?>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</body>
</html>
__________________
Airkish is offline