PHP Server Status.

Status
Not open for further replies.
N

Nathan

Guest
The first code I would like to present is a server status code.

What is it used for?
The name should be self explanitory, it displays the current status for a server. Status being "Online" and "Offline". It's a very, very, very, simple code to edit. Where the code states, "SERVER IP + PORT" is where you place the server's IP and the port is the port for the service, 80, 6112, etc. Ports are presented by a colon after the IP, i.e., 65.132.65.43:80.


PHP:
<?
error_reporting(0);
$IP = array(
"Login Server" => "SERVER IP + PORT",
); while(list($ServerName,$Host)=each($IP)) {
list($IPAddress,$Port)=explode(":",$Host);
if($fp=fsockopen($IPAddress,$Port,$ERROR_NO,$ERROR_STR,(float)0.5)) {
echo("<font color=\"white\"><b>Login Server</b>&nbsp;-&nbsp;<font color=\"green\"><b>Online</b></font>");
fclose($fp);
}
else {
echo ("<font color=\"black\"><b>Login Server</b>&nbsp;-&nbsp;<font color=\"red\"><b>Offline</b></font>");
}
echo ("");
}
?>
<p></p>
<?
error_reporting(0);
$IP = array(
"Map Server" => "SERVER IP + PORT",
); while(list($ServerName,$Host)=each($IP)) {
list($IPAddress,$Port)=explode(":",$Host);
if($fp=fsockopen($IPAddress,$Port,$ERROR_NO,$ERROR_STR,(float)0.5)) {
echo("<font color=\"white\"><b>Map Server</b>&nbsp;&nbsp;-&nbsp;<font color=\"green\"><b>Online</b></font>");
fclose($fp);
}
else {
echo ("<font color=\"black\"><b>Map Server</b>&nbsp;&nbsp;-&nbsp;<font color=\"red\"><b>Offline</b></font>");
}
echo ("");
}
?>
<p></p>
<?
error_reporting(0);
$IP = array(
"Char Server" => "SERVER IP + PORT",
); while(list($ServerName,$Host)=each($IP)) {
list($IPAddress,$Port)=explode(":",$Host);
if($fp=fsockopen($IPAddress,$Port,$ERROR_NO,$ERROR_STR,(float)0.5)) {
echo("<font color=\"white\"><b>Char Server</b>&nbsp;&nbsp;-&nbsp;<font color=\"green\"><b>Online</b></font>");
fclose($fp);
}
else {
echo ("<font color=\"black\"><b>Char Server</b>&nbsp;&nbsp;-&nbsp;</font><font color=\"red\"><b>Offline</b></font>");
}
echo ("");
}
?>


The format of the code is setup for a game server, you can add and remove servers as needed or rename the servers.

I don't know the server IP.
Ping the URL. For Windows boxes do the following.
Start > Run > CMD > type "ping websiteurl.xxx"
When typing the ping command take away the quotations and do NOT put "type" before the command.

I don't know the port for the server.
According to the server type (HTTP/FTP/SQL/ETC) the ports will vary. I have taken the liberty of listing the common ones below.

HTTP - 80
FTP - Varies
SQL - 1186

For FTP you will need to contact the server administrator, if you are the server administrator then do a port scan.
Start > Run > CMD > type "netstat -a > C:\myports.txt"
When typing the command take away the quotations and do NOT put "type" before the command.

For SQL I'm am completely not sure, that is the general MySQL server port.

For a more detailed list of server ports, you can visit:
http://www.iana.org/assignments/port-numbers

Any questions can be asked in response to this post, please no spam though.


-Dewayne
 

Vietkid58

Member
Messages
450
Reaction score
0
Points
16
so we just copy this code into a new file and save it as something like "status.php" and edit the SERVER IP + PORT part? do we leave the quotatioins or not?

edit: i left the quotes and its not working. how do we add/rename servers because mine still isn't working...

Code:
<?
error_reporting(0);
$IP = array(
"Login Server" => "70.85.87.52:80",
); while(list($ServerName,$Host)=each($IP)) {
list($IPAddress,$Port)=explode(":",$Host);
if($fp=fsockopen($IPAddress,$Port,$ERROR_NO,$ERROR  _STR,(float)0.5)) {
echo("<font color=\"white\"><b>Login Server</b>&nbsp;-&nbsp;<font color=\"green\"><b>Online</b></font>");
fclose($fp);
}
else {
echo ("<font color=\"black\"><b>Login Server</b>&nbsp;-&nbsp;<font color=\"red\"><b>Offline</b></font>");
}
echo ("");
}
?>
<p></p>
<?
error_reporting(0);
$IP = array(
"Map Server" => "70.85.87.52:80",
); while(list($ServerName,$Host)=each($IP)) {
list($IPAddress,$Port)=explode(":",$Host);
if($fp=fsockopen($IPAddress,$Port,$ERROR_NO,$ERROR  _STR,(float)0.5)) {
echo("<font color=\"white\"><b>Map Server</b>&nbsp;&nbsp;-&nbsp;<font color=\"green\"><b>Online</b></font>");
fclose($fp);
}
else {
echo ("<font color=\"black\"><b>Map Server</b>&nbsp;&nbsp;-&nbsp;<font color=\"red\"><b>Offline</b></font>");
}
echo ("");
}
?>
<p></p>
<?
error_reporting(0);
$IP = array(
"Char Server" => "70.85.87.52:80",
); while(list($ServerName,$Host)=each($IP)) {
list($IPAddress,$Port)=explode(":",$Host);
if($fp=fsockopen($IPAddress,$Port,$ERROR_NO,$ERROR  _STR,(float)0.5)) {
echo("<font color=\"white\"><b>Char Server</b>&nbsp;&nbsp;-&nbsp;<font color=\"green\"><b>Online</b></font>");
fclose($fp);
}
else {
echo ("<font color=\"black\"><b>Char Server</b>&nbsp;&nbsp;-&nbsp;</font><font color=\"red\"><b>Offline</b></font>");
}
echo ("");
}
?>
 
N

Nathan

Guest
so we just copy this code into a new file and save it as something like "status.php" and edit the SERVER IP + PORT part? do we leave the quotatioins or not?

You need to put it inside the body tags of an HTML document and upload it to a server with PHP enabled before you see the results actually taking place.
 
Status
Not open for further replies.
Top