The server space provided by the general space provider default PHP instruction MAGIC_QUOTES_GPC is on, which is open. You can then use the stripslashes () function to remove the automatically added backslash. Usage is: For example, the variable containing the string is $STR, then use the stripslashes () function to handle this string: Stripslashes ($STR), the output is the result of removing the backslash.
If 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.
But there is another problem, that is because the local PHP directive MAGIC_QUOTES_GPC is off, if this function, it will be the normal backslash also removed. This is not what we hope for.
The solution is to use the function GET_MAGIC_QUOTES_GPC () for detection, if the state is open, then remove the backslash, if the state is closed, do not remove the backslash.
The program code is as follows:
1 |
$str =$_post["str"]; Read the content assignment of STR to the $STR variable |
2 |
if (GET_MAGIC_QUOTES_GPC ()) {//if GET_MAGIC_QUOTES_GPC () is open |
3 |
$str =stripslashes ($STR); To process a string |
This article was amended 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 right to manage the server, if the use of virtual space, it can only use the latter two methods.
MAGIC_QUOTES_GPC, Magic_quotes_runtime, magic_quotes_sybase are all set to off in the PHP configuration file php.ini. As shown below:
3 |
Magic_quotes_runtime = Off |
5 |
Magic_quotes_sybase = Off |
2 use of. htaccess files
This method is only supported by the server in the case of htaccess, now the server will generally support
Add the following sentence in the program directory. htaccess file:
1 |
Php_flag MAGIC_QUOTES_GPC off |
3 Shielding in code
This method is the most portable, regardless of server configuration, as long as the support of PHP can be used.
Add the following code at the beginning of all PHP files
01 |
if (GET_MAGIC_QUOTES_GPC ()) { |
02 |
function Stripslashes_deep ($value) { |
03 |
$value =is_array ($value) array_map (' Stripslashes_deep ', $value): Stripslashes ($value); |
06 |
$_post=array_map (' Stripslashes_deep ', $_post); |
07 |
$_get=array_map (' Stripslashes_deep ', $_get); |
08 |
$_cookie=array_map (' Stripslashes_deep ', $_cookie); |
09 |
$_request=array_map (' Stripslashes_deep ', $_request); |