php - How to access $_POST variables with unknown keys in a safe way? -
my php file receives $_post variables unknown numbered keys, e.g. textpart of keys known, numbers , amount of $_post variables unknown. example: $_post[name1], $_post[name2], $_post[address1],$_post[address2].
the way see access these values means of code below:
foreach($_post $k => $v){ if(strpos($k, 'name') === 0) { //do $v } if(strpos($k, 'address') === 0) { //do $v } }
however, netbeans produces warning 'do not access superglobal $_post array directly'. looked @ php filter input functions (http://www.php.net/manual/en/function.filter-input.php) not find way access these type of $_post variables in safe way. suggestions? , starters (question beginner:), why unsafe practise access $_post vars directly?
when working variable number of keys input, format html looks like:
<input type="text" name="multi_values[1]" /> <input type="text" name="multi_values[2]" />
now can access variables this:
foreach($_post['multi_values'] $k => $v){ //do $k , $v }
furthermore can think of 2 reasons why netbeans may throw such warning: superglobals mutated while iterating on them (at least in languages support concurrency) , content of $_post
variable unstable/potentially malicious because it's controlled request of user/browser. said, in php allowed loop on $_post
array fine. check , sanitize input.
Comments
Post a Comment