php - Using cURL to findout where website redirects? -


i'm trying server redirect url. 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 header information, not showing redirects. how redirected page url ?

it's location header.

$headers = array(); $lines = explode("\n", http_head_curl('http://www.site.com', $timeout = 10));  list($protocol, $statuscode, $statusmsg) = explode(' ', array_shift($lines), 3);  foreach($lines $line){   $line = explode(':', $line, 2);   $headers[trim($line[0])] = isset($line[1]) ? trim($line[1]) : ''; }  // 3xx = redirect     if(floor($statuscode / 100) === 3)   print $headers['location']; 

Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -