RE: [PHP] ping
| From: | Chris Grigor | Date: | Wed, 27 Mar 2002 17:29:58 +0000 |
| Subject: | RE: [PHP] ping | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-90388@lists.php.net to get a copy of this message | ||
Hey Christoph
Thanks for your script, Ive just finished this one, its not that good but it works
<html>
<head>
<title>
</title>
</head>
<style>
body, td { font-family: Verdana, Arial, Helvetica, Geneva, sans-serif; font-size: 8pt; color: black;
font-weight: normal;
}
h1 { font-family: Verdana, Arial, sans-serif; font-size: 14pt; font-weight: bold; color:
#006699; }
h2 { font-family: Verdana, Arial, sans-serif; font-size: 12pt; font-weight: bold; }
th { font-family: Verdana, Arial, sans-serif; font-size: 10pt; font-weight: bold; text-align:
center; }
.h1 { font-family: Arial, sans-serif; font-size: 14pt; font-weight: bold; }
.h2 { font-family: Arial, sans-serif; font-size: 12pt; font-weight: bold; }
.label { font-family: Arial, sans-serif; font-size: 10pt; font-weight: bold; }
.normal { font-family: Arial, Helvetica, sans-serif; font-size: 10pt; }
.small { font-family: Arial, sans-serif; font-size: 8pt; color: black; font-weight: bold;}
a { color: #f79700; }
a:visited { color: #666600; }
</style>
<body bgcolor=white link=#0000ff vlink=#000099 alink=#ff0000>
<center>
<table bgcolor=#f0f0f0 border=0 cellpadding=1 cellspacing=1 >
<tr bgcolor=#f0f0f0 >
<td width="50%">
<?
exec("ping -c 2 $domain", $array);
for($index=0; $index < count($array); $index++)
{
printf("<center><b>%s</b>", $array[$index]);
}
?>
</td>
</tr>
</table>
</body>
</html>
----------------------------------------------------------------------------------
Now remember to create an html page that submits to a script called ping.php
add the following to the ping.html page for example....
<html>
<body>
<center>
<form method="POST" action="ping.php" >
<input type="text" name="domain" size="20%">
<table border="0"><tr><td>
<input type="submit" value="Submit"
name="submit"></form></td>
</td>
</tr>
</table>
</center>
</body>
</html>
----------------------------------------------------------------------------------
-----Original Message-----
From: Christoph Starkmann [mailto:kiko@nfq.de]
Sent: Wednesday, March 27, 2002 6:04 PM
To: Chris Grigor; Php-General-List (E-mail)
Subject: RE: [PHP] ping
Hi CHris!
> has anyone written a script to check if a host is alive -
> like a ping script ?
Something like this?
BTW, any hints to weak or wrong code are welcome, I'm not
this experienced with PHP ;)
Cheers, Kiko
P.S.: There are some formatting strings and some variables
stored in constants.php and a simple error function in
functions.php, but that's all, I guess anyone can change
this... ;)
<html>
<head><title>.o0o.linktest.o0o.</title></head>
<body bgcolor="#000099">
<?php
require("constants.php");
require("functions.php");
echo $f_h1 . "Check your Links" .$f_h1e;
if (isset($HTTP_GET_VARS["url"]))
{
$url = $HTTP_GET_VARS["url"];
$tempName = $url;
$tempDesc = "";
$tempPort = 80;
$tempUrl = str_replace("http://", "", $url);
$tempUrl = str_replace("/", "", $tempUrl);
$fp = fsockopen ($tempUrl, $tempPort, &$errno, &$errstr, 30);
if (!$fp)
{
echo "<br>" . $f1 . "Link fehlerhaft: " . $url . $f1_e .
"<br>\n";
}
else
{
fputs ($fp, "GET / HTTP/1.0\r\n\r\n");
$code = fgets($fp,1024);
$code = str_replace("HTTP/1.1 ", "", $code);
$code = (int)$code;
if ($code == 200) echo $f1 . "Link okay ($code)<br>" .
$f1_e;
else
{
while ($code = fgets($fp, 2048))
{
echo $f1 . ">>" . $code . "<br>" . $f1_e;
}
}
fclose($fp);
}
echo "<a href=\"" . $url . "\">" . $f_link . $tempName .
$f_linke .
"</a><br>";
}
?>
<form action="linktest.php" method="get">
<table cellspacing="0" cellpadding="0" border="0"
width="50%">
<tr>
<td>
<input type="text" name="url">
</td>
<td>
<input type="submit">
</td>
</tr>
</table>
</form>
</body>
</html>