PHP code example of knik / g-rcon

1. Go to this page and download the library: Download knik/g-rcon library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

knik / g-rcon example snippets




use Knik\GRcon\EasyGRcon;

$rcon = new EasyGRcon('source', [
    'host' => '127.0.0.1',
    'port' => 27015,
    'password' => 'rC0nPaS$word'
]);

$rcon->execute('changelevel de_dust2');
$rcon->execute('kick player');

use Knik\GRcon\GRcon;
use Knik\GRcon\Protocols\SourceAdapter;

$adapter = new SourceAdapter([
    'host' => '127.0.0.1',
    'port' => 27015,
    'password' => 'rC0nPaS$word',
]);

$rcon = new GRcon($adapter);

$rcon->execute('changelevel de_dust2');
$rcon->execute('kick player');

$rcon->kick('playername');
$rcon->ban('player');

$rcon->sendMessage('Hello players!');