I have a php + curl function that captures the "HTTP 301" responses. The page is named get_header.php and is located in the folder /exe:
function getheader($url)
// Use curl to fetch the HTTP Headers
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, 1); // just the header
curl_setopt($ch, CURLOPT_NOBODY, 1); // not the body
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
preg_match('/Location: (.*)\n/', $output, $matches);
// if no redirect header then return the original url
return isset($matches[1]) ? $matches[1] : $url;
}
echo(getheader($_GET['url']));
However, I need to use this script in a classic asp page. I tried to call it via HTTP:
Dim x: Set x = CreateObject("MSXML2.ServerXMLHTTP")
Dim y: y = "http://mysite.com/exe/get_header.php?url=" & url
x.Open "GET", y, false
x.Send()
Dim z: z = x.ResponseText
Although it works, this is not the ideal solution since both pages are on the same domain. In fact it has generated slowness of requests. So how could I solve this problem? The ideal solution would be a vbscript or javascript version of my PHP function. Thanks!