Jump to content

Recommended Posts

Posted (edited)

Hello Guys.I need some PHP script for Online Players.Can somebody help me with this.

Thank You

Edited by DukeAwesome
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:

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


×
×
  • Create New...

AdBlock Extension Detected!

Our website is made possible by displaying online advertisements to our members.

Please disable AdBlock browser extension first, to be able to use our community.

I've Disabled AdBlock