I thought I finally found a great host for my Drupal powered site, but was severly dissapointed when I discovered that the php configuration settings chould NOT be changed in any way. I've searched the Drupal site high and low for a fix for this, but have been unsuccessful. Yesterday I finally discovered a fix for this, so for everyone out there avoiding using quotes in their posts or those who have abandoned Drupal becuase of annoying backslashes - this should fix it for you. I created a function like this:

function esac($text) {
$text = eregi_replace('"', '"', $text);
return stripslashes($text);
}

Which removes escape characters that are instered when things are posted and magic_quotes_gpc is on. All you need to do now is add this function to the areas from which data is retreived and data is posted. The main two functions that do this is check_output() and check_form(). Just whack this function into those two functions and your problem should be solved, as long as the module you are using displays data using these functions and uses the standard form functions.

function check_form($text) {
return esac(drupal_specialchars($text, ENT_QUOTES));
}

function check_output($text) {
if (isset($text)) {
$text = esac($text);

// filter content on output:
$text = filter($text);
.....
}

Comments

Michael_Lessard_micles.biz’s picture

Are you using a recent version of Drupal 4.2? For some testers (with sites that are hosted virtually), magic_quotes problems vanished with the new .htaccess file (in later versions of Drupal 4.2).

Michael Lessard

Michael Lessard
webmaster of Quebec City "democracy in action" media

Anonymous’s picture

They did not vanish for me, because if I upload your .htaccess the server returns 500 Internal Error.

If the above fix will not work, I give up with Drupal, though I picked this CMS from among many, many that I searched through...

fab121’s picture

I have fix the warning issue by Drupal 4.3.1 engine by creating a php.ini file forcing magic_quotes to 0.

But, I'm using htmlarea.module and I keep getting quotes in it. It this common.inc fix oing to work also for htmlarea.module or do I have to hack it ?

mwexler’s picture

Please reference http://drupal.org/node/view/1657, http://drupal.org/node/view/2745, and http://drupal.org/node/view/2410 each of which addresses this problem.

http://drupal.org/node/view/2745 in particular provides a simple function which can be added to common.inc and eliminates this problem without having to change multiple files. Not sure exactly how or why it works, but it did work for me. I had the .htaccess problem as well; most hosting providers restrict what settings can be overridden this way.

Annoying problem, requiring the .htaccess is sort of a hack. I like the code approach better; doesn't require that you have complete control over your server configuration.

Michael