|
Source Code for HTTP Ping
Make sure you copy all the code for each file and paste it into a file with
the same name I've provided.
This is the source of: http_ping.php
This is the only file you'll really need.
<?php
/*
Title: HTTP Ping Utility
Filename: http_ping.php
Function: Check for a status code 200 from a webserver
Date last modified: 10 May 2005
Coder: Leif Gregory
E-mail: http_ping@devtek.org
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<meta http-equiv="pragma" content="no-cache" />
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1" />
<meta http-equiv="content-language" content="en-us" />
<meta name="revisit-after" content="14 days" />
<meta name="robots" content="follow,index" />
<meta name="rating" content="general" />
<title>DevTek's HTTP Ping Utility</title>
<meta name="author" content=" Leif Gregory " />
<meta http-equiv="reply-to" content="http_ping@devtek.org" />
<meta name="keywords" content="http head ping html form status 200 ok url uri up respond live server" />
<meta name="description" content="Devtek HTTP Ping Utility checks for status 200 response" />
<meta name="abstract" content="Devtek HTTP Ping Utility checks for status 200 response" />
<style type="text/css">
@import url("site.css");
</style>
<link rel="stylesheet" type="text/css" title="Site CSS" href="site.css" />
</head>
<body>
<div class="roundBorder" style="text-align: center;">
<h1>DevTek's HTTP Ping Utility</h1>
<form method="post" action="<? echo $_SERVER['PHP_SELF']; ?>">
URL: <input type="text" name="URL" value="<? echo $_POST['URL']; ?>">
<input type="submit" name="submit" value="Test!">
</form>
<?
if (isset($_POST['URL']))
{
$type = "HEAD"; # HEAD, GET, POST
$httpVersion = "HTTP/1.0"; # 1.0 or 1.1
$userAgent = ""; # Optional
$accept = "application/xhtml+xml"; # Optional
//Sanitize input
$notallowed = array("\"", "\'", " ", "`", "!", "@", "#", "$", "%", "^", "*", "(", ")", "{", "}", "[", "]", "|", ";", "<", ">", ",");
$temp = str_replace($notallowed, "", $_POST['URL']);
//Get rid HTTP://
$temp = str_replace("http://", "", $temp);
//Adding a trailing slash if one doesn't exist on just a domain input
$temp = !strstr($temp, "/") ? $temp . "/" : $temp;
//Pull out the host
preg_match("/^(.*?)[\/]/", $temp, $host);
//Pull out the path/page
preg_match("/(\/.*)/", $temp, $resource);
$host = $host[1];
$resource = isset($resource[1]) ? $resource[1] : "/";
//Testing if we can open a socket to the server
if (!@$fp = fsockopen($host, 80, $errno, $errstr, 30))
echo '<p style="color: red; font-weight: bold; size: 150%;"> ' . strtoupper($host) . ' did not respond to a socket connection. This most likely means that this host is completely down or non-existant.</p>';
else
{
fputs($fp, $type . " " . $resource . " " . $httpVersion . "\r\nHost: " . $host . "\r\nAccept: " . $accept . "\r\n\r\n");
$response = fgets($fp);
if (preg_match("/.*200 OK.*/", $response))
{
echo '<p style="color: green; font-weight: bold; font-size: 150%;"> ' . strtoupper($host) . ' is alive!</p>';
}
else
echo '<p style="color: orange; font-weight: bold; size: 150%;"> ' . strtoupper($host) . ' is alive, accepting the socket connection, but did not return a status 200 OK. This most likely means the resource you requested "' . $resource . '" does not exist.</p>';
}
echo 'The response was: ' . $alive_respones = isset($response) ? $response : "No Response";
}
?>
</div>
</body>
</html>
This is the source of: site.css
You don't need to edit this page, but if you'd like to change the
colors and such, you're more than welcome.
body {
background: #FFFFFF;
color: Black;
font-family: Tahoma, Arial, sans-serif;
font-size: 12px;
}
.mainpage {
margin-right: 10px;
margin-left: 10px;
}
.tableoutset {
border: 3px outset #ffcc00;
}
.tableinset {
border: 3px inset #ffcc00;
}
p.pagetitle {
color: #483D8B;
font-size: xx-large;
background: #ffcc00;
font-weight: bold;
}
p.pagetitle2 {
color: #FFFFFF;
font-size: xx-large;
background: slategray;
font-weight: bold;
}
p.pagesubtitle {
color: white;
font-size: x-large;
font-weight: bold;
background: mediumslateblue;
padding-top: 1px;
padding-bottom: 1px;
padding-left: 3px;
}
p.pagesubtitle2 {
color: darkslateblue;
font-size: x-large;
font-weight: bold;
}
td.main {
border: 3px green;
font-size: small;
background-color: #7B68EE;
}
p.nav {
font-size: small;
background-color: #FFFFFF;
border: 2px Black;
}
td.nav {
font-size: small;
background-color: #FFFFFF;
border: 5px Green;
}
p.inset {
border-style: inset;
padding: 10px;
}
p.buttonize {
border-style: outset;
color: #7B68EE;
font-size: large;
text-align: center;
padding-top: 3px;
padding-bottom: 3px;
width: 200px;
}
p.success {
border-style: outset;
color: green;
text-align: center;
padding-top: 3px;
padding-bottom: 3px;
}
p.warning {
border-style: outset;
color: orange;
text-align: center;
padding-top: 3px;
padding-bottom: 3px;
}
p.error {
border-style: outset;
color: red;
text-align: center;
padding-top: 3px;
padding-bottom: 3px;
}
img.floatLeft {
float: left;
margin: 4px;
}
img.floatRight {
float: right;
margin: 4px;
}
img.center {
display: block;
margin-left: auto;
margin-right: auto;
}
div.roundBorder {
color: black;
background-color: white;
margin-left: 20%; /* was .25in */
margin-right: 20%;
/* max-width: 7in; */
clear: both;
padding: 6px;
border: 2px solid #069; /* was #cc0 */
border-radius: 1em;
-moz-border-radius: 1em;
}
|