----------------------------------------------------------------------------------------------------
For example, the following login code:
if ($l = @mysql_connect (' localhost ', ' root ', ' 123 ')) or Die (' Database connection failed ');
mysql_select_db (' Test ');
Mysql_set_charset (' UTF8 ');
$sql = ' Select ' from test where username = "$username" and password = "$password";
$res = mysql_query ($sql);
if (mysql_num_rows ($res)) {
Header (' location:./home.php ');
}else{
Die (' input error ');
}
----------------------------@chenwei Black-eyed poet --------------------------
Note that the above SQL statement, there is a great security risk, if you use the following universal password and universal user name, then you can easily access the page:
1. $sql = ' SELECT * FROM test where username = "* * *" and password = "* * *" or 1 = "1";
Obviously, the universal password for this SQL statement is: * * * "or 1 =" 1
2. $sql = ' SELECT * FROM test where username = "* * *" UNION SELECT * FROM users/* and password = "* * *";
Forward slash * indicates that the following does not execute, MySQL support Union union query, so directly query out all the data; So the universal user name for this SQL statement is: * * * "UNION SELECT * FROM users/*
However, this injection is only for SQL statements in code, if $sql = "SELECT * FROM Test where username = $username and password = $password";
The above injection is at least useless, but the method is the same;
After using PDO, SQL injection can be completely avoided, and in this fast-developing era, the framework is rampant, without much consideration for SQL injection.
----------------------------------------------------------------------------------------------------
http://www.bkjia.com/PHPjc/819111.html www.bkjia.com true http://www.bkjia.com/PHPjc/819111.html techarticle ----------------------------------------------------------------------------------------------------such as the following login code: if ($l = @mysql_connect (' localhost ', ' root ' ...