Skip to content

Instantly share code, notes, and snippets.

@wisecrab
Last active January 19, 2016 15:33
<?php
function checkForRedirects($URL) {
$ch = curl_init($URL);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_exec($ch);
$original_status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_setopt($ch,CURLOPT_FOLLOWLOCATION,true);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_exec($ch);
$original_url = $URL;
$destination_url = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
$destination_status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$redirect_count = curl_getinfo($ch, CURLINFO_REDIRECT_COUNT);
$page_size = curl_getinfo($ch, CURLINFO_SIZE_DOWNLOAD);
curl_close($ch);
$code = array(
'original_url' => $original_url,
'destination_url' => $destination_url,
'original_status_code' => $original_status_code,
'destination_status_code' => $destination_status_code,
'redirect_count' => $redirect_count,
'page_size' => $page_size,
);
return $code;
}
$page_status = checkForRedirects('http://yahoo.com');
var_dump($page_status);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment