I though of two options.
one is to use regex ...
Code: Select all
preg_match("^(location:|location:))", $page);I would prefer the second of course... but... does it allways comes on the fifth line?
Moderator: General Moderators
Code: Select all
preg_match("^(location:|location:))", $page);No.pedrotuga wrote:I would prefer the second of course... but... does it allways comes on the fifth line?
Code: Select all
<?php
function foo($url) {
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
$s = curl_exec($ch);
curl_close($ch);
$s = explode("\n", $s);
foreach($s as $n=>$h) {
echo $h;
if ( 0===strpos($h, 'Location:') ) {
echo 'Line #', $n+1, "\n\n";
break;
}
}
}
foo("http://perl.org");
foo("http://microsoft.com/ie");
foo("http://swiftmailer.sf.net");
?>HTTP/1.1 302 Found
Date: Fri, 01 Jun 2007 22:31:24 GMT
Server: Apache/2.0.55 (Unix) mod_ssl/2.0.55 OpenSSL/0.9.7a
Location: http://www.perl.org/
Line #4
HTTP/1.1 301 Moved Permanently
Connection: close
Date: Fri, 01 Jun 2007 22:34:20 GMT
Server: Microsoft-IIS/6.0
X-Powered-By: ASP.NET
Location: http://www.microsoft.com/ie
Line #6
HTTP/1.1 302 Found
Date: Fri, 01 Jun 2007 22:31:25 GMT
Server: Apache/1.3.33 (Unix) PHP/4.3.10
Location: http://swiftmailer.sourceforge.net/
Line #4