As stated on php manual urlencode is for encoding query part of url, so why should urlencode be used to encoded data before sending via curl too as these are $_POST values and not query part?
foreach ($data as $key => $value) {
$value = urlencode($value);
$req .= "&$key=$value";
}
//
curl_setopt($ch, CURLOPT_POSTFIELDS, $req);
If this is recommended to do, so why this is not necessary to encode posted data via form before processing a submitted form (not for curl, but just processing form I mean.) ?
Does this mean curl is sending data differently than a submitted form does?
You can do:
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
instead of the foreach
loop. When you give an array, the parameters are posted using multipart/form-data
encoding.
You shouldn't call urldecode
in the processing form, because PHP automatically decodes the parameters before putting them into $_GET
or $_POST
.