many servers use this script:
<?php
echo "<b>Real</b> Online Players in Server: ".(1200+rand(1,100));
?>
or u can use this:
cronjob.php
<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
file_put_contents("online.txt",'0');
}
$result = $conn->query("SELECT COUNT(`online`) as online_ppl FROM `characters` WHERE `online`='1'");
if ($result->num_rows > 0) {
$row = $result->fetch_assoc();
file_put_contents("online.txt",$row['online_ppl']);
}
} else {
file_put_contents("online.txt",'0');
}
$conn->close();
?>
https://www.w3schools.com/php/php_mysql_select.asp
example every 5~10min.
and then print in website
<?php
echo file_get_contents("online.txt");
?>