IT BS Help

PHP CURL follow redirect to get HTTP status

in Coding

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

 

 

$url = ‘http://example.com/’;
$code = FALSE;

$options[‘http’] = array(
‘method’ => “HEAD”
);

$context = stream_context_create($options);

$body = file_get_contents($url, NULL, $context);

foreach($http_response_header as $header)
{
sscanf($header, ‘HTTP/%*d.%*d %d’, $code);
}

echo “Status code (after all redirects): $code<br>\n”;

0