1. 示例代码
搭建环境:
PHP/5.6.40/Nginx/1.24.0/Mysql/5.0.11
<?php$server="localhost";$username="root";$password="password";$db_connect=mysql_connect($server,$username,$password) or die("Unable to connect to the MySQL!"); mysql_select_db('sql',$db_connect); if(!isset($_POST['mail'])) {
die("POST submission mail.\n");}$mail = $_POST['mail'];$filter_chain = array(FILTER_DEFAULT, FILTER_SANITIZE_ADD_SLASHES, FILTER_VALIDATE_EMAIL, FILTER_SANITIZE_STRING);for($i=0; $i < count($filter_chain); $i++){
if(filter_var($mail, $filter_chain[$i]) === false){
die("Invalid Email.\n"); }}

文章讨论了PHP代码中的SQL注入漏洞,指出尽管使用了部分过滤器,但邮件地址验证不严导致攻击者可利用。作者推荐使用PDO预处理语句来防止此类漏洞,提供了一个修复示例。
最低0.47元/天 解锁文章
2126

被折叠的 条评论
为什么被折叠?



