#36604 [Fbk->Csd]: get_headers
| From: | bjori@php.net | Date: | Sat, 04 Mar 2006 00:48:32 +0000 |
| Subject: | #36604 [Fbk->Csd]: get_headers | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-93902@lists.php.net to get a copy of this message | ||
ID: 36604
Updated by: bjori@php.net
Reported By: chentie at livedoor dot cn
-Status: Feedback
+Status: Closed
Bug Type: *URL Functions
Operating System: freebsd 5
PHP Version: 5.1.2
New Comment:
This bug has been fixed in CVS.
Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
Thank you for the report, and for helping us make PHP better.
Has been fixed in CVS for a while now.
http://cvs.php.net/viewcvs.cgi/php-src/ext/standard/http_fopen_wrapper.c?r1=1.99.2.8&r2=1.99.2.9&diff_format=u
Previous Comments:
------------------------------------------------------------------------
[2006-03-03 16:18:36] mike@php.net
Please try using this CVS snapshot:
http://snaps.php.net/php5.1-latest.tar.gz
For Windows:
http://snaps.php.net/win32/php5.1-win32-latest.zip
------------------------------------------------------------------------
[2006-03-03 13:23:34] chentie at livedoor dot cn
conside => consider
------------------------------------------------------------------------
[2006-03-03 13:09:04] chentie at livedoor dot cn
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 this bug report at http://bugs.php.net/?id=36604&edit=1