No matter what script or what server you use there will be a strategy for dealing with Magic Quotes. It's a frustrating subject for everyone concerned and PHP have plans to remove the confusion in version 6. Until then, and probably a long time afterwards, many installations will come across problems and this page provides a few ways in which they maybe overcome.
The .htaccess file is a configuration files used by the Apache web software to alter it's configuration on the fly. It is the most flexible tool in a webmasters armoury and always worth checking your hosting package utlises it. Place the following line in it and your magic quotes problems are at an end:
php_flag magic_quotes_gpc off
Some hosts allow you to edit your own PHP.INI file. The problem with this method is some hosts require you copy the PHP.INI file to every folder where PHP runs so this can be an impracticle solution. In most cases the host that offers this feature will also allow you to use the above .htaccess method so it is definetly worth checking that out too. If you are out of luck then this is the line you need to add to your PHP.INI file (anywhere will do):-
; Magic quotes for incoming GET/POST/Cookie data.
magic_quotes_gpc = Off
; Magic quotes for runtime-generated data
magic_quotes_runtime = Off
Most windows servers are setup correctly by default which is good news as there's nothing you can do as they offer no runtime modification. The only solution is to plead with the host to switch them off via the PHP.INI file. If they won't do that for you then you are screwed and all you can do is move to another host.
Magic Quotes have been a major frustration for programming and webmaster alike. Here's a way to deal with them if you have trouble in any external scripts or third party scripts:
1. Create a file called stripMagicQuotes.inc.php and add the following code:
<?php function stripMagicQuotes($arr) { if (!is_array($arr)) { return stripslashes($arr); } else { return array_map('stripMagicQuotes', $arr); } } if (get_magic_quotes_gpc()) { $_GET = stripMagicQuotes($_GET); $_POST = stripMagicQuotes($_POST); } ?>
2. Now add the following line at the top of your /mysql_config.php file:
| include "stripMagicQuotes.inc.php"; |
3. Save the changes and test your site - be ready for total disaster! If you make even the smallest punctuation mistake your whole site can fail! Here's what to do if that happens. Open the /mysql_config.php file and place two forward slashes in front of the "include" statement (it is noted with some irony that the very things we are trying to eliminate will save our asses at this point), and should look like this:-
| //include "stripMagicQuotes.inc.php"; |
Your site will now be back up and you can investigate the error in stripMagicQuotes.inc.php