note 70636 added to function.array-filter

From: Date: Sun, 22 Oct 2006 16:19:04 +0000
Subject: note 70636 added to function.array-filter
Groups: php.notes 
Request: Send a blank email to php-notes+get-118979@lists.php.net to get a copy of this message
If you have a form with multiple checkbox having ID element as value for selection in a list, you probably have a SQL request like : $req="SELECT ... WHERE ID IN (".implode(',', array_keys($choices)).")"; without quote before and after choices keys because they are numeric values... but in fact, they can be string values, and a SQL injection problem. with array_filter, you can easily filter bad values : <?php $choices=array('A'=>'on', -1=>'on', 0=>'on', 1=>'on', 12=>'on', "1)or 1=1--"=>'on'); print_r($choices); $choices=array_filter(array_keys($choices), 'is_numeric'); print_r($choices); ?> will print : <?php Array ( [A] => on [-1] => on [0] => on [1] => on [12] => on [1)or 1=1--] => on ) Array ( [1] => -1 [2] => 0 [3] => 1 [4] => 12 ) ?> ---- Server IP: 217.174.203.10 Probable Submitter: 83.112.148.82 ---- Manual Page -- http://www.php.net/manual/en/function.array-filter.php Edit -- https://master.php.net/note/edit/70636 Del: integrated -- https://master.php.net/note/delete/70636/integrated Del: useless -- https://master.php.net/note/delete/70636/useless Del: bad code -- https://master.php.net/note/delete/70636/bad+code Del: spam -- https://master.php.net/note/delete/70636/spam Del: non-english -- https://master.php.net/note/delete/70636/non-english Del: in docs -- https://master.php.net/note/delete/70636/in+docs Del: other reasons-- https://master.php.net/note/delete/70636 Reject -- https://master.php.net/note/reject/70636 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#118979) next »