This will make you your own server status page!
Result: An awesome server status page
If you need help, post here
Step One: Make a new php file, call it Server_Status.php
Step Two: Make a SQL Database, and remember the username and password and database name.
Step Three: Open your php file, and place this in
Code:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Server Status Page</title>
</head>
<body bgcolor="#000000" text="#FFFFFF">
<?
session_set_cookie_params(1200);
session_start();
// This function is to connect to the database
function connectDB() {
$con = mysql_connect("localhost", "SQLUSER", "SQLPASSWORD") or die(mysql_error());
if (!$con) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db("SQLDATABASE") or die(mysql_error());
}
$Link = mysql_connect ("localhost", "SQLUSER", "SQLPASSWORD");
$Result = mysql_db_query ("SQLDATABASE", "SELECT * from `serverstatus`", $Link);
$User = "USERNAME";
$Pass = "PASSWORD";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<p>
<center>
<b>Server Status</b><br />
<?php
if ($_GET['id'] == "register") {
echo "<form action=\"?id=submit\" method=\"post\">You can only add online servers to this list.<br /><br />Server Name:<br /><input type=\"text\" name=\"name\" /><br />Server IP:<br /><input type=\"text\" name=\"ip\" /><br />Port:<br /><input type=\"text\" name=\"port\" /><br /><br /><input type=\"submit\" value=\"Submit\" /></form><p><br />Click <a href=\"Server_Status.php\">here</a> to go to the main page.<br /></p>";
} else if($_GET['id'] == "submit") {
$Server_Name = $_POST['name']; $Server_IP = $_POST['ip']; $Server_Port = $_POST['port'];
if (($Server_Name != NULL) && ($Server_IP != NULL) && ($Server_Port != NULL)) {
$checkReg = @fsockopen("$Server_IP", "$Server_Port", $errno, $errstr, 1);
if($checkReg) {
connectDB();
mysql_query("SELECT * FROM `serverstatus` WHERE `Name`='$Server_Name' OR `IP`='$Server_IP'");
if(mysql_affected_rows() == 1){
echo "That server is already on the list!";
} else{
mysql_query("INSERT INTO `serverstatus` (`Name`, `IP`, `Port`, `Uptime`, `Total`) VALUES ('$Server_Name', '$Server_IP', '$Server_Port', '1', '1')");
echo "<br />Your Server has been successfully added to the list!";
}
} else {
echo "Invalid information or the server is down.<br />";
}
} else {
echo "You did not fill in all of the required information!";
}
} else if($_GET['id'] == "login") {
echo "<form action=\"?id=admin\" method=\"post\"><input type=\"text\" name=\"user\" /> Username<br /><br /><input type=\"password\" name=\"pass\" /> Password<br /><br /><input type=\"submit\" value=\"Submit\" /></form>";
} else if($_GET['id'] == "admin") {
if ($_SESSION['admin'] == 1) {
echo "<table><tr><td class=\"header\"><u>Server Name</u></td><td class=\"header\"><u>Server Status</u></td></tr>";
while ($Row = mysql_fetch_array ($Result)) {
$checkCurr = @fsockopen("$Row[IP]", "$Row[Port]", $errno, $errstr, 1);
echo "<tr><td class=\"lista\">$Row[Name]</td><td class=\"lista\">";
if($checkCurr) {
echo "<form action=\"Server_Status.php?id=delete_$Row[Name]\" method=\"post\"><input type=\"submit\" value=\" Online - Delete\" /></form></td></tr>";
} else {
echo "<form action=\"Server_Status.php?id=delete_$Row[Name]\" method=\"post\"><input type=\"submit\" value=\" Offline - Delete\" /></form></td></tr>";
}
}
echo "</table>";
} else {
$Username = $_POST['user']; $Password = $_POST['pass'];
if ((isset($Username)) && (isset($Password)) && ($Username != NULL) && ($Password != NULL) && ($Username == $User) && ($Password == $Pass)) {
$_SESSION['admin'] = 1;
echo "Login successful!<br />Reload this page to continue.";
} else {
echo "Incorrect login information, please try again.";
}
}
} else {
$IDVAR = $_GET['id'];
if (isset($IDVAR)) {
if ($_SESSION['admin'] == 1) {
$remove = "delete_";
$ServName = str_replace($remove, "", $IDVAR);
connectDB();
mysql_query("DELETE FROM `serverstatus` WHERE `Name`='$ServName'") or die(mysql_error());
echo "Deleted successfully";
}
} else {
echo "<table><tr><td class=\"header\"><u>Server Name</u></td><td class=\"header\"><u>Server Status</u></td><td class=\"header\"><u>IP Address</u></td><td class=\"header\"><u>Port</u></td><td class=\"header\"><u>Uptime</u></td></tr>";
if ($Result) {
while ($Row = mysql_fetch_array ($Result)) {
connectDB();
$checkCurr = @fsockopen("$Row[IP]", "$Row[Port]", $errno, $errstr, 1);
$total = $Row[Total] + 1;
echo "<tr><td class=\"lista\">$Row[Name]</td><td class=\"lista\">";
if($checkCurr) {
$uptime = $Row[Uptime] + 1;
echo "<img src=\"online.gif\" alt=\"online\" />";
$UpdateDB = mysql_query("UPDATE `serverstatus` SET `Uptime` = $uptime WHERE `Uptime` = $Row[Uptime]");
} else {
echo "<img src=\"offline.gif\" alt=\"offline\" />";
}
$UpdateDB2 = mysql_query("UPDATE `serverstatus` SET `Total` = $total WHERE `Total` = $Row[Total]");
echo "</td><td class=\"lista\">$Row[IP]</td><td class=\"lista\">$Row[Port]</td><td class=\"lista\">";
$accuracy = $uptime/$total;
if ($accuracy == 1) {
$accuracy = $accuracy * 100;
} else {
$accuracy = 100 - $uptime/$total;
}
echo "$accuracy%</td></tr>";
}
} else {
$create = 'CREATE TABLE `serverstatus` (
`Name` VARCHAR (20) NOT NULL,
`IP` VARCHAR (50) NOT NULL,
`Port` VARCHAR (6) NOT NULL,
`Uptime` VARCHAR (999999) NOT NULL,
`Total` VARCHAR (999999) NOT NULL,
PRIMARY KEY (`Name`)
)';
mysql_query($create);
}
echo "</table>";
}
}
?>
<p>
<b></b><br />
<a href="Server_Status.php?id=register">Click Here to add your server to the List</a><br />
<a href="Server_Status.php">Refresh</a><br />
<? if($_SESSION['admin'] == 1) { echo "<a href=\"Server_Status.php?id=admin\">Administrator Panel</a><br />"; } else { echo "<a href=\"Server_Status.php?id=login\">Administrator Login</a><br />"; } ?>
<a href="smf">Visit the Fourms</a>
<br />
</a>
</p>
</center>
</body>
</html>
Now,
SQLUSERNAME = Your sql username, fill it in both times
SQLPASSWORD = The password, fill it in both times
SQLDATABASE= Your sql databse, fill it in both times
USERNAME = The admin username//Make one up
PASSWORD = The admin password // make one up
Step Four
Save the following images
As online.gif and offline.gif
Step Five:
Upload them to your website! Make sure they are in the same place.
Example
public html
-> Server_Status.php
-> online.gif
-> offline.gif
Thats the required structure.
Please Note: Bashscape is not my site it is a friends
Enjoy