';
$ipList = file_get_contents('overlayer-log.txt');
$ipListExploded = explode(PHP_EOL, $ipList);
$personInFileOrNot = 'not'; // only write slow PHP file when new person is found
$past15Minutes = date('d-m-Y H:i:s', strtotime('-15 minute', strtotime(date('d-m-Y H:i:s'))));
//echo 'countTest: '.count($ipListExploded).', $past15Minutes: '.$past15Minutes.'
';
if (count($ipListExploded) >= 2) {
$builder = '';
$inFileIpCount = 0;
foreach($ipListExploded as $ipyDatey) {
if (strlen($ipyDatey) >= 3) {
$dataJson = json_decode($ipyDatey, true);
$ipy = $dataJson['ip'];
$datey = $dataJson['syd'];
//echo 'Testing for oldness: $ipy: '.$ipy.', $datey: '.$datey."\n";
if (strtotime($datey) <= strtotime($past15Minutes)) {
//echo 'Ignore as old data. '."\n";
} else {
//echo 'Keep existing data as within 15 minutes. '."\n";
$inFileIpCount = $inFileIpCount + 1;
$builder.= $ipyDatey.PHP_EOL;
if ($ipPrivate == $ipy) { // ip in file is the same and new (within a minute)
//echo 'reinclude ip as same person and still new: '.$ipy.' datey: '.$datey.'
';
$personInFileOrNot = 'in';
}
}
}
}
if ($personInFileOrNot == 'not') {
$builder.= '{"ip": "'.$ipPrivate.'", "utc": "'.gmdate('Y/m/d H:i:s').'", "syd": "'.date('d-m-Y H:i:s').'"}';
//echo 'Writing ($inFileIpCount: '.$inFileIpCount.'): '.$builder.'
';
file_put_contents('overlayer-log.txt', '');
file_put_contents('overlayer-log.txt', $builder.PHP_EOL);
$inFileIpCount = $inFileIpCount + 1;
}
$ipsOnline = $inFileIpCount; // want to read this via JS every intialLoad
} else {
//echo '1 or less in "current ips file" so just writing single IP to text file.
';
file_put_contents('overlayer-log.txt', '{"ip": "'.$ipPrivate.'", "utc": "'.gmdate('Y/m/d H:i:s').'", "syd": "'.date('d-m-Y H:i:s').'"}'.PHP_EOL);
$ipsOnline = 1;
}
}
if (!isset($ipsOnline)) {
$ipsOnline = 1;
}
header('Content-Type: application/json');
echo json_encode($ipsOnline);
?>