Create GetOnlinePlayers.php

This commit is contained in:
vbawol 2015-04-05 09:01:35 -05:00
parent 11b5033b53
commit 6ac2996573

View File

@ -0,0 +1,31 @@
<?php
/*
Example PHP code - Returns list of online player names.
Requires: PHP5 and https://github.com/phpredis/phpredis installed
by [VB]AWOL - EpochMod.com
This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.
http://creativecommons.org/licenses/by-sa/4.0/
*/
$instance = 'NA123'; // change this to match your servers instanceID
$redis = new Redis();
$redis->pconnect(127.0.0.1, 6379, 2.5, "Server1");
$redis->auth("yourlongasspasswordhere");
$data = $redis->get('PLAYERS:' . $instance);
$onlineUIDs = json_decode($data);
// loop though online player UID's
foreach ($onlineUIDs as $key => $UID) {
// get player name
$dataRaw = $redis->get('PlayerData:' . $UID);
$data = json_decode($dataRaw);
// print player name
echo '<p>'. $data[0].'</p>';
}
?>