note 112168 added to function.in-array

From: Date: Mon, 13 May 2013 07:30:36 +0000
Subject: note 112168 added to function.in-array
Groups: php.notes 
Request: Send a blank email to php-notes+get-194789@lists.php.net to get a copy of this message
Beware when using this function to validate user input: $a = array('0' => 'Opt 1', '1' => 'Opt 2', '2' => 'Opt 3'); $v = 'sql injection'; var_dump(in_array($v, array_keys($a))); This will result : true; array_keys($a) will cast array keys to int instead of string ! then when in_array will compare it will cast 'sql injection' to int 0 ! Beware of this! ---- Server IP: 69.147.83.199 Probable Submitter: 188.191.34.187 ---- Manual Page -- http://php.net/manual/en/function.in-array.php Edit -- https://master.php.net/note/edit/112168 Del: integrated -- https://master.php.net/note/delete/112168/integrated Del: useless -- https://master.php.net/note/delete/112168/useless Del: bad code -- https://master.php.net/note/delete/112168/bad+code Del: spam -- https://master.php.net/note/delete/112168/spam Del: non-english -- https://master.php.net/note/delete/112168/non-english Del: in docs -- https://master.php.net/note/delete/112168/in+docs Del: other reasons-- https://master.php.net/note/delete/112168 Reject -- https://master.php.net/note/reject/112168 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#194789) next »