Hi, I am trying to create a script which searches through a MySQL column which contains URLs and check the URLs to see if they are up OR down. At the moment I am getting no results added into the database e.g. 1 = UP, 0 = DOWN.
Can someone please see where I’m going wrong on the below code?
<?php
include 'db.php';
function Visit(){
$agent = "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.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);
//echo curl_error($ch);
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if($httpcode>=200 && $httpcode<300) return true;
else return false;
}
$query = sprintf("SELECT client_ID, website FROM clients") or die(mysql_error());
$result = mysql_query($query);
while ($row = mysql_fetch_assoc($result)) {
echo $row['website'];
echo $row['client_ID'];
$visitid = $row['client_ID'];
$visiturl = $row['website'];
$visitstatus = Visit($visiturl)? 1 : 0;
//echo $status;
$upquery = sprintf("update clients set status=%d where id=%d", $visitstatus, $visitid);
$upresult = mysql_query($upquery);
}
?>