Magic Quotes Hell

So, I have a large app that works great, I move it over to another host, everything great except... I edit a page in the online editor (which uses tinyMCE), save it, and it appears back on the page with extra quotes, so what was:

<span class="title">GUARANTEE</span>

has become

<span class="\"title\"">GUARANTEE</span>

- actually worse because tiny mce is converting the extra quote in it to:
<span class="\&quot;title\&quot;">GUARANTEE</span>

I've added these to every script that either pulls data out or puts data into a database:

ini_set('magic_quotes_gpc','Off');
ini_set('magic_quotes_runtime','Off');
ini_set('magic_quotes_sybase','Off');

which I got from some web site. Unfortunately it does absolutely nothing at all. I guess it's something to do with stripslashes/addslashes and the default behaviour of that?

This app can sit on any possible host, is there a generic way that I can ensure this is worked out via a function (checking on values, running the appropriate behaviour? The server i developed this on doesnt use any magic_quotes or add/stripslashes in the actual php code and works perfectly, which is how i want it to be every time.

Thanks!
Matt


LVL 6
MatthewPAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Oddsen84Commented:
The answer might lie in the question... If you are using an online editor to edit it most likely has an html spescial char converter that converts all html chars into the aformentioned &nbsp; and similars. Could you try to edit the could the hard way by using notepad or wordpad?? See if this makes any difference :)
0
Oddsen84Commented:
Just as a piece of extra info. The ? and other characters are so called control characters and are therefor interpreted in a different way than other characters.
0
Rok-KraljCommented:
It is hell... And I feel it... So put this regulation code to top of each script:


  // undo magic quotes 
  if (get_magic_quotes_gpc()) { // undo deprecated php magic_quotes feature 
    $in = array(&$_GET, &$_POST, &$_COOKIE); 
    while (list($k,$v) = each($in)) { 
      foreach ($v as $key => $val) { 
        if (!is_array($val)) { 
          $in[$k][$key] = stripslashes($val); 
          continue; 
        } 
        $in[] =& $in[$k][$key]; 
      } 
    } 
    unset($in); 
  }

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Rok-KraljCommented:
So, this code detects setting... And if it is on, then it undoes directive...

DO NOT CHANGE ANY OF YOUR CODE, JUST ADD THIS TO TOP!

:D
0
MatthewPAuthor Commented:
Brilliant, thank you!

I've been through this before and couldn't remember what I did last time, only that I spent far longer on it that I really should. This works spot on.

Have to add, I am so glad they've deprecated this.

Thanks again.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.