How to turn off php magic quotes: Set the "magic_quotes_gpc", "magic_quotes_runtime", and "magic_quotes_sybase" options to "Off" in the PHP configuration file php.ini.
Recommended: "PHP Video Tutorial"
PHP Close Magic Quotes
1. Modify the PHP configuration file php.ini
This method is only suitable when you have the right to manage the server. If you use a virtual space, you can only use the last two method.
Set magic_quotes_gpc, magic_quotes_runtime, and magic_quotes_sybase all to off in the PHP configuration file php.ini.
As shown below:
magic_quotes_gpc = Off magic_quotes_runtime = Off magic_quotes_sybase = Off
2. Using .htaccess file
This method is only supported when the server supports htaccess, and most current servers generally support it
Add the following sentence to the .htaccess file in the program directory:
php_flag magic_quotes_gpc Off
3. Shield in the code
This method is the most portable and does not need to consider the server configuration. It can be used if it supports PHP.
Add the following code at the beginning of all PHP files
if(get_magic_quotes_gpc()){ function stripslashes_deep($value){ $value=is_array($value)?array_map('stripslashes_deep',$value):stripslashes($value); return $value; } $_POST=array_map('stripslashes_deep',$_POST); $_GET=array_map('stripslashes_deep',$_GET); $_COOKIE=array_map('stripslashes_deep',$_COOKIE); $_REQUEST=array_map('stripslashes_deep',$_REQUEST); }
For more related programming knowledge, please visit:Programming Learning Website! !
The above is the detailed content of How to turn off php magic quotes?. For more information, please follow other related articles on the PHP Chinese website!