Home >Backend Development >PHP Tutorial >How Can I Disable Magic Quotes on Shared Hosting Without php.ini Access?

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

Patricia Arquette
Patricia ArquetteOriginal
2024-11-25 06:04:101049browse

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 );
}

The above is the detailed content of How Can I Disable Magic Quotes on Shared Hosting Without php.ini Access?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn