note 74795 added to function.stream-context-create

From: Date: Fri, 27 Apr 2007 16:36:09 +0000
Subject: note 74795 added to function.stream-context-create
Groups: php.notes 
Request: Send a blank email to php-notes+get-125924@lists.php.net to get a copy of this message
Something to keep in mind when creating SSL streams (using https://): <?php $context = context_create_stream($context_options) $fp = fopen('https://url', 'r', false, $context); ?> One would think - the proper way to create a stream options array, would be as follows: <?php $context_options = array ( 'https' => array ( 'method' => 'POST', 'header'=> "Content-type: application/x-www-form-urlencoded\r\n" . "Content-Length: " . strlen($data) . "\r\n", 'content' => $data ) ); ?> THAT IS THE WRONG WAY!!! Take notice to the 3rd line: 'https' => array ( The CORRECT way, is as follows: <?php $context_options = array ( 'http' => array ( 'method' => 'POST', 'header'=> "Content-type: application/x-www-form-urlencoded\r\n" . "Content-Length: " . strlen($data) . "\r\n", 'content' => $data ) ); ?> Notice, the NEW 3rd line: 'http' => array ( Now - keep this in mind - I spent several hours trying to trouble shoot my issue, when I finally stumbled upon this non-documented issue. The complete code to post to a secure page is as follows: <?php $data = array ('foo' => 'bar', 'bar' => 'baz'); $data = http_build_query($data); $context_options = array ( 'http' => array ( 'method' => 'POST', 'header'=> "Content-type: application/x-www-form-urlencoded\r\n" . "Content-Length: " . strlen($data) . "\r\n", 'content' => $data ) ); $context = context_create_stream($context_options) $fp = fopen('https://url', 'r', false, $context); ?> ---- Server IP: 69.39.81.135 Probable Submitter: 68.82.232.33 ---- Manual Page -- http://www.php.net/manual/en/function.stream-context-create.php Edit -- https://master.php.net/note/edit/74795 Del: integrated -- https://master.php.net/note/delete/74795/integrated Del: useless -- https://master.php.net/note/delete/74795/useless Del: bad code -- https://master.php.net/note/delete/74795/bad+code Del: spam -- https://master.php.net/note/delete/74795/spam Del: non-english -- https://master.php.net/note/delete/74795/non-english Del: in docs -- https://master.php.net/note/delete/74795/in+docs Del: other reasons-- https://master.php.net/note/delete/74795 Reject -- https://master.php.net/note/reject/74795 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#125924) next »