note 107529 modified in function.mysql-real-escape-string by danbrown
| From: | danbrown@php.net | Date: | Thu, 10 May 2012 20:52:44 +0000 |
| Subject: | note 107529 modified in function.mysql-real-escape-string by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-187837@lists.php.net to get a copy of this message | ||
This small function walks through a complete array without a "normal" loop and
convert all potentially "bad" inputs like $_POST and $_GET to mysql conform
strings. <?php function
db_conform($s) { 	if (!is_array($s))
mysql_real_escape_string($s); 	function
db_conform_array_callback(&$item, $key) { echo $key; $item = db_conform($item);
} 	array_walk($s,
'db_conform_array_callback'); 	return
$s; } $_POST =
db_conform($_POST); ?>
--was--
This small function walks through a complete array without a "normal" loop and convert all
potentially "bad" inputs like $_POST and $_GET to mysql conform strings.
function db_conform($s)
{
if (!is_array($s)) mysql_real_escape_string($s);
function db_conform_array_callback(&$item, $key) { echo $key; $item = db_conform($item); }
array_walk($s, 'db_conform_array_callback');
return $s;
}
$_POST = db_conform($_POST);
http://php.net/manual/en/function.mysql-real-escape-string.php