magic quotes agony

Posted on 2009-02-12
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.

Question by:DJ_AM_Juicebox

Accepted Solution

r_bielak earned 1000 total points
ID: 23631010
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


Assisted Solution

digital0iced0 earned 1000 total points
ID: 23631413
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


Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses
Course of the Month16 days, 15 hours left to enroll

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question