We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now


magic quotes agony

Medium Priority
Last Modified: 2012-05-06

I'm sending some data to a PHP script via a POST. It contains single quotes and stuff like that which should NOT be escaped. However it also has backslashes too as valid data. So if I use stripslashes, that will remove my valid backslashes too?

My hosting company doesn't give me a .htaccess file, I set magic quotes to OFF in the php.ini file and copied it into all directories, but it's still adding the backslashes.

Watch Question

Hi there...

You can try to encode text before sending to php by using javascript
check out this site: http://www.the-art-of-web.com/javascript/escape/

and such encoded (encodeURI) text decode using function (not mine) in php

function utf8Urldecode($value)
    if (is_array($value)) {
        foreach ($value as $key => $val) {
            $value[$key] = utf8Urldecode($val);
    } else {
        $value = preg_replace('/%([0-9a-f]{2})/ie', 'chr(hexdec($1))', (string) $value);
    return $value;

Open in new window

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
You could use this, even though its inefficient.  But I guess its better than nothing.

if (get_magic_quotes_gpc()) {
   function stripslashes_deep($value)
       $value = is_array($value) ?
                   array_map('stripslashes_deep', $value) :
       return $value;
   $_POST = array_map('stripslashes_deep', $_POST);
   $_GET = array_map('stripslashes_deep', $_GET);
   $_COOKIE = array_map('stripslashes_deep', $_COOKIE);
   $_REQUEST = array_map('stripslashes_deep', $_REQUEST);

Open in new window

Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.