0

It's pain in the *** with magic quote on on the share server, and I am giving up on upload another php.ini to overwrite the share host php.ini, because then other problem occurr, (PDO in configure but not loaded and ect) I tried .htaccess which give a 500 error.

so i have found this solution is pretty good and works well How to turn off magic quotes on shared hosting?

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 );
}

Until i start to post array to the server

<select name="gropu[]">
<option value="1">2</option>
<option value="2">1</option>
<option value="3">3</option>
</select>

then i have the following errro

Warning: stripslashes() expects parameter 1 to be string, array given in index.php on line 18

Please help me on this, it really annoying me while developing something ok on the localhost and once upload to the server it just all wrong...

Community
  • 1
  • 1
Bill
  • 17,872
  • 19
  • 83
  • 131
  • Also note, that `parse_str` function depends on magic quotes option, so you have to unquote them on the result if you are using that function. – Marius Balčytis May 14 '13 at 00:44

1 Answers1

1

I usually run this on initialization:

// attempt to disable 'magic quotes' at runtime
@ini_set('magic_quotes_runtime', 0);
@ini_set('magic_quotes_sybase', 0);

// strip slashes if that didn't work
if(get_magic_quotes_gpc()){
  function _strip_slashes_ref(&$var){
    $var = stripslashes($var);
  }

  array_walk_recursive($_POST,    '_strip_slashes_ref');
  array_walk_recursive($_GET,     '_strip_slashes_ref');
  array_walk_recursive($_COOKIE,  '_strip_slashes_ref');
  array_walk_recursive($_REQUEST, '_strip_slashes_ref');
}

Magic quotes are removed in 5.4, so you might want to do this only if:

version_compare(PHP_VERSION, '5.4.0') < 0
nice ass
  • 16,471
  • 7
  • 50
  • 89
  • Really? you can kill it in the runtime? yeah i think the share host that i am using is less than 5.4 -_- Thanks for the help mate – Bill May 14 '13 at 00:39
  • [Apparently you can't](http://php.net/manual/en/security.magicquotes.disabling.php). `magic_quotes_runtime` can be disabled on runtime though – nice ass May 14 '13 at 00:44
  • 1
    `array_map` applies the callback to the first level only – nice ass May 14 '13 at 08:43