Hi, i have decided to make a code for people as they keep asking for a server status page.First make a new table in your database called servers with 3 feilds,
id auto increcement int(11) primary
host varcher(250)
port varchar(250)CREATE TABLE `servers` (
`id` int(11) NOT NULL auto_increment,
`host` varchar(250) NOT NULL default '',
`port` varchar(250) NOT NULL default '',
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=5 ;
Now create a php page, it can be called whatever you want :eek: as long as its a php document, dont forget to edit the database details...
<?php
session_start();
echo "<font face=arial size=2>";
//edit this
$host='localhost'; // this is usually localhost, but might be something else
$username='DATABASE USERNAME'; //database username here
$pass='DATABASE PASSWORD'; //database password here
$database='DATABASE NAME'; // database name here
mysql_connect ($host, $username, $pass);
mysql_select_db($database) or die('Could not connect to the Database');
$action = $_GET['action'];
if(!$action){
echo "<a href=$_SERVER[PHP_SELF]?action=1>Add new server</a><br /><table width=400><tr><td><font size=2><b>Address</d></font></td><td><font size=2><b>Port</b></font></td><td><font size=2><b>Status</b></font></td></tr>";
$query = mysql_query("SELECT * FROM servers");
while ($row = mysql_fetch_array($query)){
@$fp = fsockopen($row[host], $row[port], $no, $str, 4);
if($fp){
echo "<tr><td>$row[host]</td><td>$row[port]</td><td><font face=arial color=#00ff00><b>Online</b></font></td></tr>";
}else{
echo "<tr><td>$row[host]</td><td><font face=arial color=#ff0000><b>Offline</b></font></td></tr>";
}}
echo "</table><br /><a href=$_SERVER[PHP_SELF]?action=1>Add new server</a>"; }
if($action>0){
echo "<a href=$_SERVER[PHP_SELF]>Back to server list</a><br />";
if(isset($submit)){
@$fp = fsockopen($_POST[host], $_POST[port], $no, $str, 4);
if($fp){
$number = mysql_num_rows(mysql_query("SELECT * FROM servers WHERE host='$_POST[host]'"));
if($number==0){
mysql_query("INSERT INTO servers(`host`, `port`)VALUES('$_POST[host]', '$_POST[port]')");
echo "$_POST[host] $_POST[port] has succesfully been added to the database"; }
if($number>0){ echo "This host has already been submited to our database"; }
}else{
echo "There was a problem connecting to the set server, please check the feilds<br />
<form action='$_SERVER[PHP_SELF]?action=1' method=post name=form>
<table width=400>
<tr><td valign=left>host:(without http://)</td><td><input type=text name=host value=$_POST[host] /></td></tr>
<tr><td valign=left>Port:</td><td><input type=text name=port value=$_POST[port] /></td></tr>
<tr><td valign=left><input type=submit name=submit value=Submit /></td></tr>
</table></form>
"; }}
if(!isset($submit)){
echo "
<form action='$_SERVER[PHP_SELF]?action=1' method=POST name=form>
<table width=400>
<tr><td valign=left><font size=2>Host:(without http://)</font></td><td><input type=text name=host value=$_POST[host] /></td></tr>
<tr><td valign=left><font size=2>Port:</font></td><td><input type=text name=port value=$_POST[port] /></td></tr>
<tr><td valign=left><input name=submit type=submit value=Submit></td></tr>
</table></form>
"; }
echo "<br /><a href=$_SERVER[PHP_SELF]>Back to server list</a>";
}
echo "</font>";
?>