php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #22705 fopen_wrappers and http headers as client
Submitted: 2003-03-14 11:04 UTC Modified: 2003-04-07 16:09 UTC
From: phpdig at toiletoine dot net Assigned:
Status: Closed Package: Feature/Change Request
PHP Version: 4.3.0 OS: Linux k2.4.18, apache 2.0.44
Private report: No CVE-ID: None
 [2003-03-14 11:04 UTC] phpdig at toiletoine dot net
Hello,

In my php project (phpDig, a small robot/search engine), i needed to send "Cookie: ..." HTTP header when i use the file() function with http fopen_wrappers.
I needed this in order to spider sites setting cookies (session, selected language, etc...).

The only solution i found was inserting my custom headers in the ini constant "user_agent" with ini_set.

This works, but i mean that could be removed in an future release of PHP :

ini_set('user_agent','phpdig/1.6'."\n".'Cookie: foo=bar'."\n".'Cookie: bar=foo');

Of course, setting other client headers in "user_agent" is not very good.

I suggest to add another ini constant ("http_client_headers" ?) that will contain those headers. I mean it would be useful.

Best regards,
Antoine Bajolet


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-04-07 16:09 UTC] pollita@php.net
This bug has been fixed in CVS.

In case this was a PHP problem, 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/.
 
In case this was a documentation problem, the fix will show up soon at
http://www.php.net/manual/.

In case this was a PHP.net website problem, the change will show
up on the PHP.net site and on the mirror sites in short time.
 
Thank you for the report, and for helping us make PHP better.

This feature has been implemented using the new streams context API (to be documented soon).

Here's an example:

<?php
  $opts = array(
    'http'=>array(
      'header'=>"Cookie: foo=bar\r\n" . 
                "Accept-language: en\r\n"
    )
  );

  $context = stream_context_create($opts);

  $fp = fopen('http://www.example.com/', 'r', false, $context);
  fpassthru($fp);
  fclose($fp);
?>

Other context options are available for the http wrapper such as 'method' (GET or POST only, PUT and HEAD to be added later), and 'content' (send after request headers, typically used for POST data).

If you name an http request header which is already provided by another mechanism (such as User-Agent) the value you provide in 'header' will override the other value.
From:, Host:, and Authentication: can also be overridden in this manner.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Oct 17 14:01:27 2024 UTC