- 主动攻击(主动攻击server)
- 被动攻击(上传木马程序,用户訪问时触发http陷阱)
- client验证
- 服务端验证(输入值验证。输出值转义)
php
$clean = array();
$mysql = array();
$clean['last_name'] = "O'Reilly";
$mysql['last_name'] = mysql_real_escape_string($clean['last_name']);
$sql = "INSERT
INTO user (last_name)
VALUES ('{$mysql['last_name']}')";
?>
mysqli_real_escape_string
(PHP 5)
mysqli::real_escape_string -- mysqli_real_escape_string — Escapes
special characters in a string for use in an SQL statement, taking into account the current charset of the connection
尽量使用为你的数据库设计的转义函数。
假设没有,使用函数addslashes()是终于的比較好的方法。
$str
)返回字符串。该字符串为了数据库查询语句等的须要在某些字符前加上了反斜线。
这些字符是单引號(')、双引號(")、反斜线(\)与
NUL( NULL
字符)。
- '&' (ampersand) becomes '&'
- '"' (double quote) becomes '"' when
ENT_NOQUOTES
is not set. - "'" (single quote) becomes ''' (or ') only when
ENT_QUOTES
is
set. - '<' (less than) becomes '<'
- '>' (greater than) becomes '>'
php
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdGQ5MDExMDV0ZA==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="">
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdGQ5MDExMDV0ZA==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="">