PHP预防SQL注入

PHP预防SQL注入的三种方式

一,检验数据类型

1.数字类型

is_numeric() 函数

2.字符串类型(强校验)

preg_match(“/^[a-zA-Z0-9]{6,}$/”,变量)

二,过滤和转义特殊字符

addslashes()对特定字符进行转义

mysqli_real_escape_string()对特定字符进行转义

三,利用mysql的预编译机制

$stmt = mysqli_prepare($db,$sql);

mysqli_stmt_bind_param();

mysqli_stmt_execute();

mysqli_stmt_bind_result();

mysqli_stmt_fetch();

猜你喜欢

转载自blog.csdn.net/u013800308/article/details/82252811