NYCPHP Meetup

NYPHP.org

[nycphp-talk] How to pass on variables with POST without using a form

David Krings ramons at gmx.net
Wed Sep 20 20:45:59 EDT 2006


At 08:04 PM 9/20/2006, you wrote:
>CED wrote:
> > Good thing for HTMLentities eh?
>
>Not really, you don't want to use htmlentities in this situation.  You
>are escaping your values into POST data so you should use urlencode, as
>in the example below.
>
>The easiest way I've found to do this is as follows:
>
>$myvars = array(
>   'item1' => 'value1',
>   'item2' => 'value2',
>);
>
>$postdata = array();
>foreach ($myvars as $k => $v) {
>   $postdata[] = urlencode($k) .'=' . urlencode($v);
>}
>$postdata = implode('&',$postdata);
>
>curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);
>
>By running both your keys and values through urlencode, you'll be sure
>that you won't end up with mangled post data, no matter what the values'
>contents are.
>
>If you want to be really ahead of the curve you can use
>ini_get('arg_separator.output') in place of '&' in the implode.
>
>Dan


That's it? WOW! That's just a few lines of code! Thank you!
Now, I need to see how I build the rest of the script around this, which 
shouldn't be that tricky.

This is awesome! Shows how much more I still have to learn. :/

         David K. 




More information about the talk mailing list