I'm trying to get server redirect url. I have tried
function http_head_curl($url,$timeout=10)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); // in seconds
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_NOBODY, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$res = curl_exec($ch);
if ($res === false) {
throw new RuntimeException("cURL exception: ".curl_errno($ch).": ".curl_error($ch));
}
return trim($res);
}
echo http_head_curl("http://www.site.com",$timeout=10);
Result is;
HTTP/1.1 301 Moved Permanently Date: Sun, 12 May 2013 23:34:22 GMT Server: LiteSpeed Connection: close X-Powered-By: PHP/5.3.23 Set-Cookie: PHPSESSID=0d4b28dd02bd3d8413c92f71253e8b31; path=/; HttpOnly X-Pingback: http://site.com/xmlrpc.php Content-Type: text/html; charset=UTF-8 Location: http://site.com/ HTTP/1.1 200 OK Date: Sun, 12 May 2013 23:34:23 GMT Server: LiteSpeed Connection: close X-Powered-By: PHP/5.3.23 Set-Cookie: PHPSESSID=630ed27f107c07d25ee6dbfcb02e8dec; path=/; HttpOnly X-Pingback: http://site.com/xmlrpc.php Content-Type: text/html; charset=UTF-8
It shows almost all header information, but not showing where it redirects. How do I get the redirected page url ?