I want to add something like a counter of how many are online in a little bubble bottom right.
I generated the JS required, which I know where to put, but how do I upload my PHP code for the session count? and not have it overwritten on an automatic update of the software? Can I access this information through the API? and would that be easier?
thanks

I generated the JS required, which I know where to put, but how do I upload my PHP code for the session count? and not have it overwritten on an automatic update of the software? Can I access this information through the API? and would that be easier?
thanks

<?php
// online.php — returns {"count": N} based on recent PHP session files
header('Content-Type: application/json');
// how far back to consider "online"
$windowSeconds = 300; // 5 minutes
// session dir (defaults to php.ini's session.save_path)
$savePath = ini_get('session.save_path');
if (!$savePath) {
// common fallback; adjust if needed
$savePath = sys_get_temp_dir();
}
// count files modified within the window
$count = 0;
$now = time();
if (is_dir($savePath) && ($h = opendir($savePath))) {
while (($f = readdir($h)) !== false) {
if (strpos($f, 'sess_') === 0) {
$fp = $savePath . DIRECTORY_SEPARATOR . $f;
if (@filemtime($fp) >= ($now - $windowSeconds)) {
$count++;
}
}
}
closedir($h);
}
echo json_encode(['count' => $count], JSON_UNESCAPED_SLASHES);