I want to turn off PHP's magic quotes. I don't have access to php.ini.
When I tried to add php_flag magic_quotes_gpc off
to my .htaccess file, I get a 500 internal server error. This is what my .htaccess file looks like:
AddType x-mapp-php5 .php
php_flag magic_quotes_gpc off
Then I tried to use ini_set('magic_quotes_gpc', 'O')
, but that had no effect.
How do I turn magic quotes off?
If you can't turn it off, here is what I usually do:
It will be placed in the database in its proper format.
This will solve the problem of getting "Class 'PDO' not found" when you create a local php.ini file.
If you can't turn off magic quotes using the htaccess file (for reasons already given by Pete Bailey) just:
Add the lines
magic_quotes_gpc = Off
magic_quotes_runtime = Off
magic_quotes_sybase = Off
extension=pdo.so
extension=pdo_mysql.so
Save it to the directory/ies in which your scripts are executing.
Update: if you want to have just one copy of the new php.ini file then add this line to your root .htaccess file:
Obviously you need to move the ini file to this location of it's not there already.
Hope that saves someone the 2 hours it's just taken me!
The php_flag and php_value inside a .htaccess file are technically correct - but for PHP installed as an Apache module only. On a shared host you'll almost never find such a setup; PHP is run as a CGI instead, for reasons related to security (keeping your server neighbours out of your files) and the way phpsuexec runs scripts as 'you' instead of the apache user.
Apache is thus correct giving you a server error: it doesn't know about the meaning of php_flag unless the PHP module is loaded. A CGI binary is to Apache an external program instead, and you can't configure it from within Apache.
Now for the good news: you can set up per-directory configuration putting there a file named 'php.ini' and setting there your instructions using the same syntax as in the system's main php.ini. The PHP manual lists all settable directives: you can set those marked with PHP_INI_PERDIR or PHP_INI_ALL, while only the system administrator can set those marked PHP_INI_SYSTEM in the server-wide php.ini.
Note that such php.ini directives are not inherited by subdirectories, you'll have to give them their own php.ini.
Different hosting providers have different procedures for doing this, so I would ask on their forums or file a support request.
If you can't turn them off, you could always using something like this which will escape input regardless of whether magic quotes are on or off:
if your hosting provider using cpanel, you can try copying php.ini into your web directory and edit it with magic_quotes_gpc = off
How about
$_SERVER
?