Jump to content

Recommended Posts

Posted

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");
?>

 

Posted
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

Posted
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 :laughing:

Posted (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 by AlmostGood

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...