Home  >  Article  >  Backend Development  >  How to turn off php magic quotes?

How to turn off php magic quotes?

青灯夜游
青灯夜游Original
2020-08-17 10:12:022748browse

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.

How to turn off php magic quotes?

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!

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