note 95784 added to function.http-build-query
| From: | irish | Date: | Thu, 21 Jan 2010 21:31:17 +0000 |
| Subject: | note 95784 added to function.http-build-query | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-165178@lists.php.net to get a copy of this message | ||
When using the http_build_query function to create a URL query from an array for use in something
like curl_setopt($ch, CURLOPT_POSTFIELDS, $post_url), be careful about the url encoding.
In my case, I simply wanted to pass on the received $_POST data to a CURL's POST data, which
requires it to be in the URL format. If something like a space [ ] goes into the http_build_query,
it comes out as a +. If you're then sending this off for POST again, you won't get the
expected result. This is good for GET but not POST.
Instead you can make your own simple function if you simply want to pass along the data:
$post_url = '';
foreach ($_POST AS $key=>$value)
$post_url .= $key.'='.$value.'&';
$post_url = rtrim($post_url, '&');
You can then use this to pass along POST data in CURL.
$ch = curl_init($some_url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_url);
curl_exec($ch);
Note that at the final page that processes the POST data, you should be properly filtering/escaping
it.
----
Server IP: 69.147.83.197
Probable Submitter: 140.80.199.91
----
Manual Page -- http://www.php.net/manual/en/function.http-build-query.php
Edit -- https://master.php.net/note/edit/95784
Del: integrated -- https://master.php.net/note/delete/95784/integrated
Del: useless -- https://master.php.net/note/delete/95784/useless
Del: bad code -- https://master.php.net/note/delete/95784/bad+code
Del: spam -- https://master.php.net/note/delete/95784/spam
Del: non-english -- https://master.php.net/note/delete/95784/non-english
Del: in docs -- https://master.php.net/note/delete/95784/in+docs
Del: other reasons-- https://master.php.net/note/delete/95784
Reject -- https://master.php.net/note/reject/95784
Search -- https://master.php.net/manage/user-notes.php