Form wont return array when using this function to overcome magic quotes?
To counteract magic quotes I have this function set at the top of every page.
However it seems to be affecting when I have an array in a form <input type="checkbox" name="check[]" />
.
if ( in_array( strtolower( ini_get( 'magic_quotes_gpc' ) ), array( '1', 'on' ) ) ) {
$_POST = array_map( 'stripslashes', $_POST );
$_GET = array_map( 'stripslashes', $_GET );
$_COOKIE = array_map( 'stripslashes', $_COOKIE );
}
I removed the function and it worked returning the full array when printing the array. However I need magic quotes off and also.
With the funciton I just get Array
returned.
How can I change the function above or overcome th开发者_开发技巧is issue?
Thanks
There is an excellent page on the php website about how to disable magic quotes, both in the .ini
file and at runtime. I highly suggest using their code instead of something homebaked.
You can use array_walk_recursive
:
function gpc_stripslashes(&$value, $key) {
$value = stripslashes($value);
}
array_walk_recursive($_GET, 'gpc_stripslashes');
Or PHP 5.3 way (although magic_quotes_gpc is off by default in 5.3):
array_walk_recursive($_GET, function (&$value, $key) {
$value = addslashes($value);
});
精彩评论