| Path : /var/www/html/main/ |
|
|
| Current File : /var/www/html/main/usersonline.php |
<?php
/*!
* Copyright Anucha Puangpaka
* Contact anucha.ppk@icloud.com 062-479-9836
*/
$token = (isset($_GET['token']) && preg_match('/^[0-9a-f]{8}$/', $_GET['token'])) ? $_GET['token'] : false;
if (!$token) {
$token = sprintf('%08x', crc32(microtime()));
}
$quadrant = ceil(date_create()->format('s') / 15);
$previousQuadrant = $quadrant - 1 < 1 ? 4 : $quadrant - 1;
$key = 'anucha_'.$quadrant;
$previousKey = 'anucha_'.$previousQuadrant;
$current = apc_fetch($key);
$previous = apc_fetch($previousKey);
if (!is_array($current)) {
$current = array();
}
if (!is_array($previous)) {
$previous = array();
}
if (count($current) < 250 && !in_array($token, $current)) {
$current[] = $token;
apc_store($key, $current, 31);
}
$output = array(
'usersOnline' => count($current) > 250 ? '250+' : count(array_unique(array_merge($current, $previous))),
'token' => $token,
);
header('Content-Type: application/json');
print json_encode($output);
exit;
?>