From: chentie at livedoor dot cn
Operating system: freebsd 5
PHP version: 5.1.2
PHP Bug Type: *URL Functions
Bug description: get_headers
Description:
------------
get_headers("http://bugs.php.net/welcometochina.php")
the result is like this:
Warning: get_headers (http://bugs.php.net/welcometochina.php): failed to
open stream: HTTP request failed! HTTP/1.1 404 Not Found
but i think it should be like this:
HTTP/1.1 404 Not Found
Content-Length: 1635
Content-Type: text/html
Server: Microsoft-IIS/6.0
X-Powered-By: ASP.NET
Date: Fri, 03 Mar 2006 11:30:47 GMT
Connection: close
and other http status code such as 403
i hate to touch you in others method,here is my code for that problem:
function get_headers($url,$format=0) {
$url=parse_url($url);
if (empty($url["path"])) {
$url["path"]="/";
}
print_r($url);
$end = "\r\n\r\n";
$fp = fsockopen($url['host'],
(empty($url['port'])?80:$url['port']), $errno, $errstr, 30);
if ($fp) {
$out = "GET {$url["path"]} HTTP/1.1\r\n";
$out .= "Host: ".$url['host']."\r\n";
$out .= "Connection: Close\r\n\r\n";
$var = '';
fwrite($fp, $out);
while (!feof($fp)) {
$var.=fgets($fp, 1280);
if(strpos($var,$end))
break;
}
print $var;
fclose($fp);
$var=preg_replace("/\r\n\r\n.*\$/",'',$var);
$var=explode("\r\n",$var);
if($format) {
foreach($var as $i) {
if(preg_match('/^([a-zA-Z -]+): +(.*)$/',$i,$parts))
$v[$parts[1]]=$parts[2];
}
return $v;
}
else
return $var;
}
}
here i didn't conside the loction of code 301,because i think
it's not the true URI ,just return the 301 response is OK
at last, sorry for my english,welcome to china 2008! ;-p
--
Edit bug report at http://bugs.php.net/?id=36604&edit=1
--
Try a CVS snapshot (PHP 4.4):
http://bugs.php.net/fix.php?id=36604&r=trysnapshot44
Try a CVS snapshot (PHP 5.1):
http://bugs.php.net/fix.php?id=36604&r=trysnapshot51
Try a CVS snapshot (PHP 6.0):
http://bugs.php.net/fix.php?id=36604&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=36604&r=fixedcvs
Fixed in release:
http://bugs.php.net/fix.php?id=36604&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=36604&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=36604&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=36604&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=36604&r=support
Expected behavior: http://bugs.php.net/fix.php?id=36604&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=36604&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=36604&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=36604&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=36604&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=36604&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=36604&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=36604&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=36604&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=36604&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=36604&r=mysqlcfg