|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #36604 get_headers
Submitted: 2006-03-03 13:09 UTC Modified: 2006-03-04 01:48 UTC
From: chentie at livedoor dot cn Assigned:
Status: Closed Package: *URL Functions
PHP Version: 5.1.2 OS: freebsd 5
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: chentie at livedoor dot cn
New email:
PHP Version: OS:


 [2006-03-03 13:09 UTC] chentie at livedoor dot cn

the result is like this:
Warning: get_headers ( 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) {
       if (empty($url["path"])) {
       $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);
           print $var; 

           if($format) {
               foreach($var as $i) {
                   if(preg_match('/^([a-zA-Z -]+): +(.*)$/',$i,$parts))
               return $v;
               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  


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2006-03-03 13:23 UTC] chentie at livedoor dot cn
conside => consider
 [2006-03-03 16:18 UTC]
Please try using this CVS snapshot:
For Windows:

 [2006-03-04 01:48 UTC]
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
Thank you for the report, and for helping us make PHP better.

Has been fixed in CVS for a while now.
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Sun May 28 16:03:40 2023 UTC