What are the differences between PHP daddslashes () and saddslashes () _php Tutorial

Source: Internet
Author: User
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: ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.