Check My Website

myit web design graphics

If you are having website issues and/or would like to know when your website is offline, then the following code will help you out in monitoring your web server uptime ... and it won't cost you anything.

You will run this php script using 'crontab' every 10 minutes (or less if you like) and you'll get an email if your site is offline.

(a) You need a control panel which has "crontab" facilities, or contact your hosting company as most of them provide it at some level - they might even setup the crontab entry for you.

In the crontab you need to add an entry that will run every 10 minutes and check your website:

*/10 * * * *     php   ./website-checker.php

(b) Then in your website code you need to add a particular identification number like this to your <head> </head> section:

<meta name="identification" content="3487hyr39rhf4hf8uhf45rf" />

(c) And lastly, you need the following piece of php code (here it's called website-checker.php) that will run every 10 minutes in the crontab and look for the above identification number in your website page code. You need to change the name of the 1 or more websites that you want to check, and change the '$recipient' email address to your email address and change the 'from' email address.

If the code finds the above '3487hyr39rhf4hf8uhf45rf' identifier in each of your one or more websites no email will be sent to you. If any one of the websites is down (and the identifier will not be found) then you'll get an email stating which website(s) are down and which are up. You'll need to go fix those websites then as the code will run every 10 minutes, so you'll have 6 emails after 1 hour.


$recipient = '';
$positive_reply = 'the site WAS detected';
$negative_reply = 'the site was NOT detected';
$headers = "From:\r\n" . 
                  "X-Mailer: php";

$date = date('m-M-Y g:i a', time());
$url_array = array("",
$email_message_positives = "";
$email_message_negatives = "";

for ($i=0; $i<sizeof($url_array); $i++){
   $ch = curl_init($url_array[$i]);
   curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
   curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 1);
   $text = curl_exec($ch);
   $test = strpos($text, "3487hyr39rhf4hf8uhf45rf");
   if ($test==false){
         //echo $negative_reply." - ".$url_array[$i]."\n";
         $email_message_negatives = 
         //echo $positive_reply." - ".$url_array[$i]."\n";
         $email_message_positives =  

if(strlen($email_message_negatives) == 0 && isset($email_message_negatives)){ 
    mail($recipient, $date." -- LIVE WEBSITES REPORT", "WEBSITES DOWN: \n\n".
    $email_message_negatives."\n\n\nWEBSITES LIVE\n\n".$email_message_positives, $headers);


We can, or course, set the code up for you and have it that you get the email report when your website is offline.