Home Pics Vidz Programs Martial Arts Links Jokes Guestbook
PHP Web Watcher
By
James Wright


PHP Web Watcher will email the webmaster if the web site is down. I made Web Watcher for my company's web site. If my company's web site is down, I need to be contacted as soon as possible. PHP Web Watcher will check every 10 minutes to see if the web site is up or not. For security reasons, I disabled the email feature for the example. WARNING: If you post this script on your site, spammers can use it to send spam using your server.

EXAMPLE

URL:
File:
Email:

No emails will be sent using the above example.



SCREENSHOT


SOURCE CODE


<?
if ($_POST['url'] != "") setcookie("url", $_POST['url'], time()+3600*24*7*4*12);
if ($_POST['file'] != "") @setcookie("file", $_POST['file'], time()+3600*24*7*4*12);
if ($_POST['email'] != "") @setcookie("email", $_POST['email'], time()+3600*24*7*4*12);
?>



<table border=0 width=750><tr><td width=350>

<form action="webwatcher.php" method="post">

<center>
<table border="0" cellpadding="0" cellspacing="0" bgcolor="white">
<tr>
<td valign="top" align="right">
URL: <input type="text" name="url" size="44" value="<? if($_POST['url']!='') echo $_POST['url']; else echo $HTTP_COOKIE_VARS['url']; ?>" >
</td></tr><tr>
<td valign="top" align="right">

File: <input type="text" name="file" size="44" value="<? if($_POST['file']!='') echo $_POST['file']; else echo $HTTP_COOKIE_VARS['file']; ?>" >
</td></tr>
<tr>
<td valign="top" align="right">
Email: <input type="text" name="email" size="44" value="<? if($_POST['email']!='') echo $_POST['email']; else echo $HTTP_COOKIE_VARS['email']; ?>" >
</td></tr>
</table>


<p><input type="submit" value="Send" /></p>
</form>
</center>


</td><td width=400>
<center>


<?php

if ($_POST['url'] == "")
{
$_POST['url'] = $_COOKIE['url'];
$_POST['file'] = $_COOKIE['file'];
$_POST['email'] = $_COOKIE['email'];
}


$Server = str_replace("http://","", $_POST['url']);
// $Server = str_replace("/", "", $Server);

if ($Server != "")
{
$Port = "80";
$File = str_replace("/","", $_POST['file']);
$File = "/".$File;
$Request = "GET " . $File . " HTTP/1.0\r\n";
$Request = $Request . "Host: " . $Server . "\r\n"; // Add attributs you want
$Request = $Request . "\r\n"; // Ending by an empty line

$From = "James@MrJamesWright.com";


$Socket = @fsockopen($Server, $Port, &$errno, &$errstr, 30);
// if(!$Socket) echo "<br><b>Can't connect to: <font color=blue>".$Server.$File."</font></b><br>$errstr ($errno)<br>";

@fputs($Socket, $Request);

while( ! ereg( "^\r?\n?$", $Line ) ) // Getting head content
$Head = $Head . @fgets($Socket, 1024);


// while(!feof($Socket)) // Getting file content
$Html = $Html . @fgets($Socket, 1024);
//echo $Html."<br><br>";


if ( strpos($Html, '200') )
{
echo "<font color=#00ff00><b>Web site is OK</b></font><br><br><br>";
$msg = "OK";
}
else
{

echo "<font color=red><b>Web site has an error</b></font><br><br><br>";
$msg = "ERROR";
}

$body = $msg."<br><br>Server: ".$Server."<br>File: ".$File;

/* while(!feof($Socket)) // Getting file content
$Html = $Html . fgets($Socket, 1024);
echo $Html."<br><br><br>";
*/
@fclose($Socket);


if ($msg == "ERROR")
if (sendmsg($_POST['email'], 'Web Site Status: '.$msg, $body, $From))
{
echo "Email sent.<br><br>";
} else { echo "Email was not sent. Sorry. Please email me at JWright295@aol.com"; }

} // end of main body

?>

</td></tr></table>

<?
function sendmsg($to, $subject, $text, $from) {
$uid = strtoupper(md5(uniqid(time())));
$header = "From: $from\nReply-To: $from\n";
$header .= "MIME-Version: 1.0\n";
$header .= "Content-Type: multipart/mixed; boundary=$uid\n";
$header .= "--$uid\n";
$header .= "Content-Type: text/plain\n";
$header .= "Content-Transfer-Encoding: 8bit\n\n";
$header .= "$text\n";
$header .= "--$uid\n";
$header .= "--$uid--";

if (mail($to, $subject, $text, "From: JamesWright@MrJamesWright.com\r\nReply-To: $from\r\n"))
{
return true;
} else { return false;}

}
?>




Home - Pics - Vidz - Programs - Jokes - Martial Arts - Links - Guestbook

Please email me at: JWright295@aol.com
Copyright © 2007  JWright295. All rights reserved.

Your IP address: 38.103.63.16
Browser: You are using:CCBot/1.0 (+http://www.commoncrawl.org/bot.html)
Operating System: Mac/? FreeBSD/? OpenBSD/?
Your ISP: 38.103.63.16



COUNTER
2745