#22705 [Opn->Csd]: fopen_wrappers and http headers as client

From: Date: Mon, 07 Apr 2003 21:09:50 +0000
Subject: #22705 [Opn->Csd]: fopen_wrappers and http headers as client
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-37293@lists.php.net to get a copy of this message
ID: 22705 Updated by: pollita@php.net Reported By: phpdig at toiletoine dot net -Status: Open +Status: Closed Bug Type: Feature/Change Request Operating System: Linux k2.4.18, apache 2.0.44 PHP Version: 4.3.0 New Comment: 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. Previous Comments: ------------------------------------------------------------------------ [2003-03-14 11:04:42] 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 ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=22705&edit=1

« previous php.bugs (#37293) next »