function fileCheck($remoteFile){
$ch = curl_init($remoteFile);
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
$data = curl_exec($ch);
curl_close($ch);
if ($data === false) {
return 'cURL failed';
}
$status = 'unknown';
if (preg_match('/^HTTP\/1\.[01] (\d\d\d)/', $data, $matches)) {
$status = (int)$matches[1];
}
return $status;
}bu fonksyonu kullan 200 veriyor sa site erişiliyordur 200 değilse erişilmiyordur
kullanım şekli;
$urlCheck = fileCheck("http://www.google.com.tr");
if($urlCheck == 200){
echo "oke";
}else{
echo "no";
}