Raised This Month: $12 Target: $400
 3% 

Solved Get playerlist with php


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
4ever16
Veteran Member
Join Date: Apr 2015
Old 12-20-2017 , 15:22   Get playerlist with php
Reply With Quote #1

Gametracker can get playerlist from HLDS servers.

Example: https://www.gametracker.com/server_i....246.31:27015/

What methods are they using?
I would also like to get playerlist from other servers and print it as a list.
How they do it?

Last edited by 4ever16; 12-26-2017 at 18:19.
4ever16 is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 12-20-2017 , 22:01   Re: Get playerlist with php
Reply With Quote #2

Have you tried searching? There are several threads that mention PHPRcon. But ultimately, it uses the public API for servers provided by Valve (IIRC, they are documented on the Steam wiki).
__________________
fysiks is offline
4ever16
Veteran Member
Join Date: Apr 2015
Old 12-21-2017 , 08:54   Re: Get playerlist with php
Reply With Quote #3

PHPRcon needs rcon password?
The site i linked you doesnt need rcon password so how they do it?
4ever16 is offline
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 12-21-2017 , 10:58   Re: Get playerlist with php
Reply With Quote #4

https://github.com/xPaw/PHP-Source-Query
__________________
klippy is offline
4ever16
Veteran Member
Join Date: Apr 2015
Old 12-21-2017 , 11:35   Re: Get playerlist with php
Reply With Quote #5

Quote:
Originally Posted by KliPPy View Post
Can you explain more how to install it just to see playerlist?

I know some php but this wasnt easy.
4ever16 is offline
4ever16
Veteran Member
Join Date: Apr 2015
Old 12-22-2017 , 04:35   Re: Get playerlist with php
Reply With Quote #6

Ok so i downloaded that PHP Query script.

/Examples/Example.php -> Edited some stuff.

But it prints playerlist like this.

Quote:
Array
(
[0] => Array
(
[Id] => 0
[Name] => Noob
)

)
How can i make so it prints only Noob?

Last edited by 4ever16; 12-22-2017 at 04:35.
4ever16 is offline
Airkish
AlliedModders Donor
Join Date: Apr 2016
Location: Lithuania
Old 12-22-2017 , 07:37   Re: Get playerlist with php
Reply With Quote #7

Quote:
Originally Posted by 4ever16 View Post
Ok so i downloaded that PHP Query script.

/Examples/Example.php -> Edited some stuff.

But it prints playerlist like this.



How can i make so it prints only Noob?
Let's say you Array name is $playerData

You can print the name like this:

PHP Code:
echo $playerData[0]['Name']; 
To print every players data you should use FOR.

PHP Code:
$totalPlayers sizeof($playerData)
for(
$i 0$i <= $totalPlayers$i++) {
echo 
$playerData[$i]['Name'];

__________________

Last edited by Airkish; 12-22-2017 at 07:41.
Airkish is offline
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
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 12-22-2017 , 16:10   Re: Get playerlist with php
Reply With Quote #9

Quote:
Originally Posted by 4ever16 View Post
Ok so i downloaded that PHP Query script.

/Examples/Example.php -> Edited some stuff.

But it prints playerlist like this.



How can i make so it prints only Noob?
I recommend that you study some of the basics of PHP (specifically, in this case, about arrays). This is not a PHP help forum.
__________________
fysiks is offline
4ever16
Veteran Member
Join Date: Apr 2015
Old 12-22-2017 , 18:26   Re: Get playerlist with php
Reply With Quote #10

Quote:
Originally Posted by Airkish View Post
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>
Thanks man great work!
4ever16 is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 11:18.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode