Jump to content

[SOLVED] Website Checker Script


JDMallion

Recommended Posts

Hi guys,

 

I want to write a PHP script to check several of the websites that we run. I will have it run each day using a CRON job therefore automatically checking our sites each morning.

 

I basically just want the script to go to each website and check that they are still up and running. Now I know that I will have to get the HTTP server response code to work out whether or not the website is up or not. But I am not 100% sure on how to do this!! A point in the right direction would be really good.

 

Thanks in advance for any help!!

Link to comment
https://forums.phpfreaks.com/topic/70450-solved-website-checker-script/
Share on other sites

Yea use cURL.

 

I hope this is what you need.

 

<?php

$yoursites=array("www.google.com","www.yahoo.com","www.73645jgfsf.com"); //Enter your all websites here as shown.

for($i=0;$i<count($yoursites);$i++)
{
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, $yoursites[$i]);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_FOLLOWLOCATION,1);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false);
curl_setopt($ch, CURLOPT_AUTOREFERER,false); 
$source = curl_exec($ch);
$httpCode = curl_getinfo($ch,CURLINFO_HTTP_CODE);
if($httpCode==200)
{
echo $yoursites[$i]." is up.<br>";
}
else
{
echo $yoursites[$i]." is down.<br>";
}
curl_close($ch);
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.