The server space provided by the general Space quotient default PHP directive MAGIC_QUOTES_GPC is on, that is, open. You can then use the stripslashes () function to remove the auto-added backslash. The usage is: for example, the variable containing the string is $STR, then use the stripslashes () function to process the string: stripslashes ($STR), the result of the output is to remove the backslash.
If the result of the output contains a backslash, the output can be processed with the stripslashes () function, that is, $str=stripslashes ($STR), save to remove the backslash contained in the output content.
However, there is another problem, that is, because the local PHP command MAGIC_QUOTES_GPC is off, if you use this function, it will be the normal backslash also removed. This is not what we want.
The solution is to use the function GET_MAGIC_QUOTES_GPC () to detect, if it is open, then remove the backslash, if the state is closed, do not remove the backslash.
The program code is as follows:
Copy the Code code as follows:
$str =$_post["str"]; Read the contents of STR to the $STR variable
if (GET_MAGIC_QUOTES_GPC ()) {//if GET_MAGIC_QUOTES_GPC () is open
$str =stripslashes ($STR); To process a string
}
This article was revised on April 25, 2012 10:08:03 as follows:
Here are three ways to solve this problem:
1. Modify PHP configuration file php.ini
This method is only suitable for the case of having the right to administer the server, if the virtual space is used, then only the latter two methods can be used.
Set MAGIC_QUOTES_GPC, Magic_quotes_runtime, magic_quotes_sybase all to off in PHP config file php.ini. As shown below:
Copy the Code code as follows:
MAGIC_QUOTES_GPC = Off
Magic_quotes_runtime = Off
Magic_quotes_sybase = Off
2 using the. htaccess file
This method is supported only in cases where the server supports htaccess, and now the server will generally support
In the program directory, add the following sentence to the. htaccess file:
Php_flag MAGIC_QUOTES_GPC Off
3 Masking in code
This method is the most portable, regardless of the server configuration, as long as the support of PHP can be used.
Add the following code at the beginning of all PHP files
Copy the Code code as follows:
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);
}
http://www.bkjia.com/PHPjc/313536.html www.bkjia.com true http://www.bkjia.com/PHPjc/313536.html techarticle The server space provided by the general Space quotient default PHP directive MAGIC_QUOTES_GPC is on, that is, open. You can then use the stripslashes () function to remove the auto-added backslash. Use a.