Parašė INFINITY· 2009 Spa. 29 22:10:19
#1
Jai rasau ne itinkama vieta prasau pekelkit jai jum blogai cia...
Radau toki server status page. Jis rodo idetus serverius kuriuos gali pridet visi. Problema tame kad kai paspaudziu add server (pries tai surasius servo detales) paraso tipo kad servas idetas sucesfully bet kai grystu i servu puslapi servo nerodo.
sita galima uzvardint betkokiu pavadinimu svarbu kad butu .php
Kodai:
<?php
session_start();
echo "<font face=\"arial\" size=\"2\">";
mysql_connect ('localhost', 'username', 'password'); //edit this
mysql_select_db('database') or die('Could not connect to the Database'); //and this
if (!$_GET[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 ($_GET[action] > 0)
{
echo "<a href=$_SERVER[PHP_SELF]>Back to server list</a><br />";
if (isset($_POST[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($_POST[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;<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>";
?>
MYSQL table:
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 ;
gal zinot kai ji pakeist galima i paprastesni varianta kad nerejktu rasyt prisijungimo duomenu cia?
mysql_connect ('localhost', 'username', 'password'); //edit this
mysql_select_db('database') or die('Could not connect to the Database'); //and this