cronCheckUrls.php
<?
//Set name of text file
$file = "urlUpResults.txt";
//Create blank file/delete contents of existing file before run rest of script
file_put_contents($file, " ");
//Build array of sites to check
$sitesArray = array("http://www.minecraft.net", "http://www.4stats.tk", "http://www.google.com", "http://www.stackoverflow.com", "http://www.brokentestwebsite.com");
foreach ($sitesArray as $value) {
if (TPBUC($value))
$upStatus = "<p>" . $value . " is up.</p>";
else
$upStatus = "<p>" . $value . " is down.</p>";
file_put_contents($file, $upStatus, FILE_APPEND);
}
//cURL function
function TPBUC($url){
$agent = "Mozilla/5.0 (compatible; TPBUC/1.0;)";$ch=curl_init();
curl_setopt ($ch, CURLOPT_URL,$url );
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch,CURLOPT_VERBOSE,false);
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch,CURLOPT_SSLVERSION,3);
curl_setopt($ch,CURLOPT_SSL_VERIFYHOST, FALSE);
$page=curl_exec($ch);
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if($httpcode>=200 && $httpcode<400) return true;
else return false;
}
?>
索引.php
<?
$file = "urlUpResults.txt";
echo "<h1>UpCheck results:<h1><br>" . file_get_contents($file);
?>