• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Need some PHP-help! [Rep++ zomg]

Helga

GZH
Joined
Feb 19, 2009
Messages
622
Reaction score
1
Location
Sweden
Heya!

I am going to make another website that shows how many players that are online on my servers.

I'm a HTML/CSS webdesigner and I am learning PHP atm, but I need some help with a PHP-script.

I want my external website to show "Players online: xxx/750"
Just like my gesior aac does. But how do I do? I know that it takes the information from the "/config/serverstatus"-file, but I don't know the code to include it.

I tested to do it the way gesior aac's has it:
Code:
<?PHP
$config[helga] = parse_ini_file('http://helgaot.com/config/serverstatus');
$config[zeltenia] = parse_ini_file('http://zeltenia.com/config/serverstatus');

 if($config['helga']['serverStatus_online'] == 1)
    echo '
		Players Online: '.$config['helga']['serverStatus_players'].' / '.$config['helga']['serverStatus_playersMax'].'<br />';						
    else
		echo '<font color="red"><b>HelgaOT server Offline</b></font>';
		
 if($config['zeltenia']['serverStatus_online'] == 1)
    echo '
		Players Online: '.$config['zeltenia']['serverStatus_players'].' / '.$config['zeltenia']['serverStatus_playersMax'].'<br />';						
    else
		echo '<font color="red"><b>Zeltenia server Offline</b></font>';
?>

But then I get those errors: http://www.zantera.net/index2.php

Thanks in advance!
 
I do believe it would be simpler just to write a class/function which counts online players directly from the database, and then displays it.
 
what about this:
Code:
<font size="1" color="white">&nbsp;&nbsp;&nbsp;Players Online: '.$config['status']['serverStatus_players'].' / '.$config['status']['serverStatus_playersMax'].'
 
PHP:
$link = mysql_connect("localhost", "mysql_user", "mysql_password");
mysql_select_db("database", $link);

$result = mysql_query("SELECT * FROM players WHERE online = 1", $link);
$players_online = mysql_num_rows($result);

That should work, the variable "$players_online" will now contain the number of players currently online.

Just stuff it in above the echo stuff, and don't forget to change the mysql user/pass and database name.
 
Nice thanks, I will test it...
But if someone spam-refresh the page it will cause some lag? The gesior aac does like a auto update on the players online every 300 seconds...
 
PHP:
$link = mysql_connect("localhost", "mysql_user", "mysql_password");
mysql_select_db("database", $link);

$result = mysql_query("SELECT * FROM players WHERE online = 1", $link);
$players_online = mysql_num_rows($result);

That should work, the variable "$players_online" will now contain the number of players currently online.

Just stuff it in above the echo stuff, and don't forget to change the mysql user/pass and database name.
Fail, If mysql connection fail it will throw your password and use MysqlI....

@Thread if you really need it badly PM me and ill give you an old server status checker via socket that i made some months ago x.x
 
Fail, If mysql connection fail it will throw your password and use MysqlI....

PHP:
$link = @mysql_connect("localhost", "mysql_user", "mysql_password");
@mysql_select_db("database", $link);

$result = @mysql_query("SELECT * FROM players WHERE online = 1", $link);
$players_online = @mysql_num_rows($result);

No error displaying. Problem solved.
 
PHP:
$link = @mysql_connect("localhost", "mysql_user", "mysql_password");
@mysql_select_db("database", $link);

$result = @mysql_query("SELECT * FROM players WHERE online = 1", $link);
$players_online = @mysql_num_rows($result);

No error displaying. Problem solved.

It still needs some timeout and make it save to a status.ini-file or something, and let it update max every 5 minutes or so?
 
Back
Top