cURL PHP Get INFO_HTTP_CODE (URL Status)

Get information link external status OK, 200 or Redirect 301, 302 + bed response url 404 or 500 with php code cURL, this very fast time loading.

<?php
//== Option check cURL active & version
$values=curl_version();
echo 'cURL Version : '.$values["version"].'<hr>';
//-----------------

$url ='https://www.google.com/xxxxxxx';
$timeout = 10;
$ch = curl_init();
// set cURL options

$opts = array(CURLOPT_RETURNTRANSFER => true, // do not output to browser
            CURLOPT_URL => $url,            // set URL
            CURLOPT_NOBODY => true,         // do a HEAD request only
            CURLOPT_TIMEOUT => $timeout);   // set timeout

curl_setopt_array($ch, $opts);
curl_exec($ch); // do it!
$http = curl_getinfo($ch, CURLINFO_HTTP_CODE); // find HTTP status
curl_close($ch); // close handle

if($http === 200 OR $http === 301 OR $http === 302) {
echo $http;
} elseif ($http === 404){ // not found page but url OK
echo $http;
} else {
echo "Page error failed.";
}
READ :  POST Ajax Jquery Form Data Json