• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 627
  • Last Modified:

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


0
MatthewP
Asked:
MatthewP
  • 2
  • 2
1 Solution
 
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
 
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

Featured Post

[Webinar] Kill tickets & tabs using PowerShell

Are you tired of cycling through the same browser tabs everyday to close the same repetitive tickets? In this webinar JumpCloud will show how you can leverage RESTful APIs to build your own PowerShell modules to kill tickets & tabs using the PowerShell command Invoke-RestMethod.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now