ID: 45092 Updated by: j...@php.net Reported By: nweibley at gmail dot com Status: Open Bug Type: cURL related Operating System: Linux (Gentoo) PHP Version: 5.2.6 New Comment:
See also bug #46896 (quite likely related) Previous Comments: ------------------------------------------------------------------------ [2008-10-10 15:25:05] php at joerg dot wedekind dot de Well I have the same prolem, using this Code in php 5.2.6: <?php $postdata = http_build_query( array( 'var1' => 'some content', 'var2' => 'doh' ) ); $opts = array('http' => array( 'method' => 'POST', 'header' => 'Cookie: testcookie=1234', 'content' => $postdata ) ); $context = stream_context_create($opts); $result = file_get_contents('http://wedekind.de/submit.php', false, $context); ?> The cookie-Information is not send to the Server, see this tracelog: 0x0000: 0020 ed69 d4ca 000a 5e4a a34a 0800 4500 ...i....^J.J..E. 0x0010: 00e7 cb3f 4000 3a06 cfea 5413 a9b3 d90b ....@.:...T..... 0x0020: ce14 e117 0050 9419 c2ce a31a b3c2 8018 .....P.......... 0x0030: 002e 3f79 0000 0101 080a 0b17 09ff a78e ..?y............ 0x0040: 6583 504f 5354 202f 7375 626d 6974 2e70 e.POST./submit.p 0x0050: 6870 2048 5454 502f 312e 310d 0a55 7365 hp.HTTP/1.1..Use 0x0060: 722d 4167 656e 743a 2050 4850 2f35 2e32 r-Agent:.PHP/5.2 0x0070: 2e36 0d0a 486f 7374 3a20 7765 6465 6b69 .6..Host:.wedeki 0x0080: 6e64 2e64 650d 0a41 6363 6570 743a 202a nd.de..Accept:.* 0x0090: 2f2a 0d0a 436f 6e74 656e 742d 4c65 6e67 /*..Content-Leng 0x00a0: 7468 3a20 3236 0d0a 436f 6e74 656e 742d th:.26..Content- 0x00b0: 5479 7065 3a20 6170 706c 6963 6174 696f Type:.applicatio 0x00c0: 6e2f 782d 7777 772d 666f 726d 2d75 726c n/x-www-form-url 0x00d0: 656e 636f 6465 640d 0a0d 0a76 6172 313d encoded....var1= 0x00e0: 736f 6d65 2b63 6f6e 7465 6e74 2676 6172 some+content&var 0x00f0: 323d 646f 68 2=doh ------------------------------------------------------------------------ [2008-05-26 15:34:59] nweibley at gmail dot com Ah, came to the solution. Line 332 of ext/curl/streams.c: if (Z_TYPE_PP(header) == IS_STRING) { Ergo, each element of the array passed as the value of the 'header' context option *must* be a string, not an associative key=>value pair. I'd propose this be more clearly documented or an additional conditional branch be added to ext/curl/streams.c to handle key=>value array pairs and especially a simple string as the header context option. This is the behavior when --with-curlwrappers is not used, and it seems highly logical that it would still stand with curlwrappers enabled. ------------------------------------------------------------------------ [2008-05-26 15:27:37] nweibley at gmail dot com Since line 324 of ext/curl/streams.c reads: if (SUCCESS == php_stream_context_get_option(context, "http", "header", &ctx_opt) && Z_TYPE_PP(ctx_opt) == IS_ARRAY) { I have changed my code to reflect passing an array as the value of 'header' in the context options. The problem still persists, however. ------------------------------------------------------------------------ [2008-05-26 15:16:09] nweibley at gmail dot com Description: ------------ Pretty simple; I'm trying to create a stream context which will send custom headers along with a simple HTTP GET request. It wasn't working so I created a second debug script to see what was up and found that PHP simply isn't including any of my custom headers. This *is not* a duplicate of bug #41051, I have tried that as well. Reproduce code: --------------- <?php //send.php $params = array('http' => array('method' => 'GET','header' => "Custom: woot")); $ctx = stream_context_create($params); $fp = fopen('http://localhost/recv.php', 'r', false, $ctx); print_r(stream_context_get_options($ctx)); print_r(stream_get_meta_data($fp)); echo stream_get_contents($fp); ?> <?php //recv.php print_r(apache_request_headers()); ?> Expected result: ---------------- Array ( [http] => Array ( [method] => GET [header] => Custom: woot ) ) Array ( [wrapper_data] => Array ( [headers] => Array ( ) [readbuf] => Resource id #4 ) [wrapper_type] => cURL [stream_type] => cURL [mode] => r [unread_bytes] => 0 [seekable] => [uri] => http://localhost/404.php [timed_out] => [blocked] => 1 [eof] => ) Array ( [User-Agent] => PHP/5.2.6-pl1-gentoo [Host] => localhost [Accept] => */* [Custom] => woot ) Actual result: -------------- Array ( [http] => Array ( [method] => GET [header] => Custom: woot ) ) Array ( [wrapper_data] => Array ( [headers] => Array ( ) [readbuf] => Resource id #4 ) [wrapper_type] => cURL [stream_type] => cURL [mode] => r [unread_bytes] => 0 [seekable] => [uri] => http://localhost/recv.php [timed_out] => [blocked] => 1 [eof] => ) Array ( [User-Agent] => PHP/5.2.6-pl1-gentoo [Host] => localhost [Accept] => */* ) ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=45092&edit=1