eromad Posted March 30, 2020 Posted March 30, 2020 (edited) Hello Guys.I need some PHP script for Online Players.Can somebody help me with this. Thank You Edited April 2, 2020 by DukeAwesome Quote
wongerlt Posted March 30, 2020 Posted March 30, 2020 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"); ?> Quote
Nightw0lf Posted March 31, 2020 Posted March 31, 2020 This is dangerous each website visitor will open a server connection, in case of website DDOS your server is good as dead. 1 Quote
wongerlt Posted March 31, 2020 Posted March 31, 2020 1 hour ago, Nightw0lf said: This is dangerous each website visitor will open a server connection, in case of website DDOS your server is good as dead. how with my solution it can be? :D Quote
Nightw0lf Posted April 2, 2020 Posted April 2, 2020 On 3/31/2020 at 1:47 PM, wongerlt said: how with my solution it can be? :D The ideal concept is to make a php script and then create a cron job to run this script every 5min for example and the php will create in a file the statistics you want, after that you can print the file as you like. See how this concept avoids public interaction with server database? also i dont recommend mysqli use PDO instead with try/catch so your passwords wont be printed on connection failures Quote
AlmostGood Posted April 2, 2020 Posted April 2, 2020 (edited) did you even look his code? its exactly what you described, it dumps results to file, he even called his example file "cronjob" cleaned example above: https://pastebin.com/raw/Si8w8emv Edited April 2, 2020 by AlmostGood Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.