Larry Garfield wrote:
On Sunday 14 January 2007 12:01 am, Jim Lucas wrote:
This is what I use, and it has worked ever time.
if ( get_magic_quotes_gpc() ) {
$_POST = array_map("stripslashes", $_POST);
}
Jim Lucas
That will break as soon as you submit an array back through a POST request,
which I do rather often. :-) You need to iterate over the array, and if an
item is an array, iterate over it recursively. array_walk() can be useful
here.
Of course, the real answer is to disable magic quotes in the first place as
they are spawn of Satan. If you're using a web host that doesn't let you do
so, get a real web host.
Had to think about that one and test, but you are right.
Up until this point, I have not had a project that I had to submit
arrays via POST. Just happens that next week, I would have started my
first project that does require me to submit via POST with arrays and I
would have found it then, but anyways, it is fixed now.
on my dev server I have PHP 4.3.11 so I had to build my own work around
for array_walk_recursive, since it is only in PHP5 and newer :(
I am pretty sure that it does what the function does in PHP5
Try this
<plaintext><?PHP
//stripslashes test
function array_walk_recursive(&$a, $b, $c=null) {
foreach ( $a AS $k => $v ) {
if ( is_array($v) ) {
array_walk_recursive($v, $b, $c);
$a[$k] = $v;
} else {
$a[$k] = $b($v, $k, $c);
}
}
return true;
}
function my_stripslashes($a, $b, $c='') {
return stripslashes($a);
}
$data[] = addslashes("Jim's new list");
$data[] = addslashes("Tom's new list");
$data[] = array(addslashes("bill's"), addslashes("Tracy's"));
var_dump($data);
array_walk_recursive($data, "my_stripslashes");
var_dump($data);
?>
Jim Lucas
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php