It is a good explanation of the difference between addslashes and mysql_real_escape_string. Although many domestic PHP coders still rely on addslashes to prevent SQL injection (including me), I still recommend that everyone strengthen checks to prevent SQL injection in Chinese. The problem with addslashes is that hackers can use 0xbf27 to replace single quotes, while addslashes only changes 0xbf27 to 0xbf5c27, which becomes a valid multi-byte character. 0xbf5c is still regarded as a single quote, so addslashes cannot successfully intercept.
Of course, addslashes is not useless. It is used for processing single-byte strings. For multi-byte characters, use mysql_real_escape_string.
In addition, for the example of get_magic_quotes_gpc in the PHP manual:
Copy the code The code is as follows:
if (!get_magic_quotes_gpc()) {
$lastname = addslashes($_POST['lastname']);
} else {
$lastname = $_POST['lastname'];
}
The above introduces stripslashes php addslashes and mysql_real_escape_string, including the content of stripslashes. I hope it will be helpful to friends who are interested in PHP tutorials.