"If a worker wants to do his job well, he must first sharpen his tools." - Confucius, "The Analects of Confucius. Lu Linggong"
Front page > Programming > How to disable magic quotes on shared hosting? No php.ini permission required

How to disable magic quotes on shared hosting? No php.ini permission required

Posted on 2025-05-03
Browse:658

How Can I Disable Magic Quotes on Shared Hosting Without php.ini Access?

Disabling Magic Quotes on Shared Hosting

Turning off magic quotes on shared hosting can be tricky, especially when you don't have access to php.ini.

Using .htaccess

Adding php_flag magic_quotes_gpc off to your .htaccess file may not always work. This directive is typically used for mod_php environments, but shared hosting providers often use suexec/FastCGI setups instead.

Custom php.ini

In such cases, you can install a custom php.ini file. Some shared hosting providers allow this for suexec/FastCGI setups.

ini_set()

Using ini_set('magic_quotes_gpc', 'O') will not turn off magic quotes. The correct value should be 0, false, or "off". However, it's important to note that magic_quotes_gpc is a PHP_INI_PERDIR setting, meaning you can't change it with ini_set().

.htaccess Alternative

Since ini_set() is not an option, you can use an .htaccess file instead. However, you must use the correct directive:

php_value magic_quotes_gpc 0

Script Workaround

If .htaccess is not allowed, you can implement a workaround script to reverse the effects of magic quotes:

if ( in_array( strtolower( ini_get( 'magic_quotes_gpc' ) ), array( '1', 'on' ) ) )
{
    $_POST = array_map( 'stripslashes', $_POST );
    $_GET = array_map( 'stripslashes', $_GET );
    $_COOKIE = array_map( 'stripslashes', $_COOKIE );
}
Latest tutorial More>

Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.

Copyright© 2022 湘ICP备2022001581号-3