EOSERV Forum > EO Server Building > Online/Offline Status Script
Page: << 1 >>
Online/Offline Status Script
Author Message
Post #203499 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
Post #203500 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
Post #203501 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
Post #203505 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
Post #203506 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
Page: << 1 >>

EOSERV Forum > EO Server Building > Online/Offline Status Script