1

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 this issue?

Thanks

eykanal
  • 26,437
  • 19
  • 82
  • 113
Stefan P
  • 1,013
  • 2
  • 18
  • 34

2 Answers2

0

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.

eykanal
  • 26,437
  • 19
  • 82
  • 113
  • perfect thanks, their code works perfectly - which is obvious it's in their own documentation! - I am not able to adjust .ini but will in my next hosting environment – Stefan P Feb 16 '11 at 20:15
0

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);
});
netcoder
  • 66,435
  • 19
  • 125
  • 142