Why does PHP cURL drop numeric keys? -
i'm trying use curl post array containing numeric indices, curl_setopt dropping numeric indices. i'm using php version 5.3.29.
here's simple script setup illustrate happening:
<?php $is_curled = isset($_get['curl']) ? !!$_get['curl'] : false; if (!$is_curled) { $url = $_server['script_uri'] . '?curl=1'; $_post['1'] = 'test1234'; // dropped because numeric $_post[234] = 'test3211'; // dropped because numeric $_post['t3'] = 'test1325'; // not dropped $_post['4t'] = 'test6347'; // not dropped $_post['_5'] = 'test3235'; // not dropped $_post['*4'] = 'test7432'; // not dropped gets next post value $_post["3"] = 'test8521'; // dropped because numeric $_post['"2"'] = 'test9472'; // not dropped because string "2" $_post["'1'"] = 'test2741'; // not dropped because string '1' gets next post value $_post["10"] = 'test1738'; // dropped because numeric $_post['test_field'] = 'test6123'; // not dropped $ch = curl_init(); curl_setopt($ch, curlopt_url, $url); curl_setopt($ch, curlopt_postfields, $_post); // drops numeric keys echo '<pre>' . print_r($_post, 1) . '</pre>'; curl_exec($ch); curl_close($ch); } else { echo '<pre>' . print_r($_post, 1) . '</pre>'; } ?> here output:
array ( [1] => test1234 [234] => test3211 [t3] => test1325 [4t] => test6347 [_5] => test3235 [*4] => test7432 [3] => test8521 ["2"] => test9472 ['1'] => test2741 [10] => test1738 [test_field] => test6123 ) array ( [t3] => test1325 [4t] => test6347 [_5] => test3235 [*4] => test8521 ["2"] => test9472 ['1'] => test1738 [test_field] => test6123 ) what's weirder, not indices dropped, values appear shifted in ones next ones dropped.
assuming sending content type application/x-www-form-urlencoded means you're sending html form data. (php curl defaults content type w3c recommended default https://www.w3.org/tr/html401/interact/forms.html#h-17.13.4).
according spec, name tokens (a.k.a. post , get parameter names )have start letter: https://www.w3.org/tr/html4/types.html#h-6.2
id , name tokens must begin letter ([a-za-z]) , may followed number of letters, digits ([0-9]), hyphens ("-"), underscores ("_"), colons (":"), , periods (".").
this why it's not being handled expect, because starting param in post body number indicated content type unsupported.
Comments
Post a Comment