GPC filtering, automatic escape of special characters in $_get,$_post,$_cookie to prevent SQL injection attacks
$_get = Saddslashes ($_get);
$_post = Saddslashes ($_post);
Copy CodeThe code is as follows:
The following is an example of daddslashes () and saddslashes () eg:saddslashes function daddslashes ($string, $force = 0, $strip = FALSE) {
Whether a string or array enforces removal
If the magic reference is not turned on or $force is not 0
if (! MAGIC_QUOTES_GPC | | $force) {
if (Is_array ($string)) {//If it is an array then loop executes this function
foreach ($string as $key = = $val) {
$string [$key] = Daddslashes ($val, $force);
}
} else {
If the magic reference is turned on or $force to 0
The following is a ternary operator that executes Stripslashes minus the backslash character if $strip is true, and then executes the addslashes
$strip is true, that is, the backslash character is first removed and then escaped for $_get,$_post,$_cookie and $_request $_request arrays contain the values of the first three arrays
Why should we remove the $string first and then escape it, because sometimes $string have two backslashes, Stripslashes is to filter out the excess backslash
$string = Addslashes ($strip? Stripslashes ($string): $string);
}
}
return $string;
}eg:saddslashes function Saddslashes ($string) {if (! MAGIC_QUOTES_GPC) {
if (Is_array ($string)) {//If an array is escaped, the value in the set is recursively escaped
foreach ($string as $key = = $val) {
$string [$key] = saddslashes ($val);
}
} else {
$string = Addslashes ($string); Escapes the single quotation mark ('), double quotation mark ("), backslash (\), and NUL (NULL character)
}
return $string;
}else{
return $string;
}
The main thing is:
Saddslashes can be used to escape every single data processing.
Copy CodeThe code is as follows:
function Saddslashes ($string) {
if (Is_array ($string)) {
foreach ($string as $key = = $val) {
$string [$key] = saddslashes ($val);
}
} else {
$string = Addslashes ($string);
}
return $string;
}
http://www.bkjia.com/PHPjc/326187.html www.bkjia.com true http://www.bkjia.com/PHPjc/326187.html techarticle //GPC filter, automatically escapes special characters in $_get,$_post,$_cookie, prevents SQL injection attacks $_get = Saddslashes ($_get); $_post = Saddslashes ($_post); Copy Code The code is as follows: ...