wesly
Joined: 24th Apr 2012
Posts: 335
Online/Offline Status Script
You can add this to your server's website to check if your EO server is online/offline.
REMEMBER TO CHANGE THE IP ADDRESS to your gameserver's IP
( I removed the last "ELSE" from the actual Code, it serves no purpose)
DOWNLOAD LINK : https://www.mediafire.com/file/5pld5w9u4ub0rtu/status.zip
Preview of the Code:
6 years, 37 weeks ago
|
Apollo
Administrator
Joined: 14th Apr 2009
Posts: 2759
Re: Online/Offline Status Script
Probably not a lot of need to declare a function or variables separately here especially if php is embedded into a basic html page unless you are calling the IP and port and this function more than once. Condensed down into the simplest form without using CSS is:
$online = '<b>Server Status: <font color="green" size=3>Online!</font>';
$offline = '<b>Server Status: <font color="red" size=3>Offline!</font>';
$server = @fsockopen('game.your-server-domanin.com', 8078, $errno, $errstr, 1.0);
if ($server)
{
echo "$online";
}
else
{
echo "$offline";
}
6 years, 37 weeks ago
|
wesly
Joined: 24th Apr 2012
Posts: 335
Re: Online/Offline Status Script
Apollo posted: (13th Aug 2017, 05:19 pm)
Probably not a lot of need to declare a function or variables separately here especially if php is embedded into a basic html page unless you are calling the IP and port and this function more than once. Condensed down into the simplest form without using CSS is:
$online = '<b>Server Status: <font color="green" size=3>Online!</font>';
$offline = '<b>Server Status: <font color="red" size=3>Offline!</font>';
$server = @fsockopen('game.your-server-domanin.com', 8078, $errno, $errstr, 1.0);
if ($server)
{
echo "$online";
}
else
{
echo "$offline";
}
sorry x.x , still new to this PHP thing, thanks for this simple code tho !
Edit: ( I deleted the " " ) from the variables, maybe someone could use this in the future.
$online = '<b>Server Status: <font color="green" size=3>Online!</font>';
$offline = '<b>Server Status: <font color="red" size=3>Offline!</font>';
$server = @fsockopen('game.your-server-domanin.com', 8078, $errno, $errstr, 1.0);
if ($server)
{
echo $online;
}
else
{
echo $offline;
}
6 years, 37 weeks ago
|
DanScott
Joined: 19th Aug 2010
Posts: 1212
Re: Online/Offline Status Script
pretty sure you can also do short hand if statements in PHP to make it look something like
echo($server ? "Online" : "Offline");
side note: When making functions, you can just return the value of the boolean rather than checking it. Example:
function eo_status($host, $port) {
return fsockopen($host, $port, $errno, $errstr, 3);
}
Which I guess is why apollo pointed out quite rightly that it's redundant (3 lines of code that could be 1 :P) ---
If money doesn't grow on trees, then why do banks have branches?
6 years, 37 weeks ago
|
Apollo
Administrator
Joined: 14th Apr 2009
Posts: 2759
Re: Online/Offline Status Script
True, but then again I guess it is just a personal preference not to throw booleans into echo just because it is a cosmetic eyesore. I would much rather leave web pages to html and css when possible and avoid ever typing echo outside of debugging. Leaving the online and offline cases
separate allow for other things to happen within those cases without cramming it into one line. Anyway, you can find all of the examples you need in the WebCP for just showing "Online" .
6 years, 37 weeks ago
| | | | | |