Home  >  Article  >  php教程  >  php 防止注入的几种办法

php 防止注入的几种办法

WBOY
WBOYOriginal
2016-06-13 10:11:561120browse

php教程 防止注入的几种办法

其实原来就是我们需要过滤一些我们常见的关键字和符合如:

select,insert,update,delete,and,*,等等

例子:

function inject_check($sql_str) {
return eregi('select|insert|update|delete|'|/*|*|../|./|union|into|load_file
|outfile', $sql_str); // 进行过滤
}

或者是通过系统函数间的过滤特殊符号

addslashes(需要被过滤的内容)

二、 php其他地方安全设置

1、register_globals = off 设置为关闭状态

2、sql语句书写时尽量不要省略小引号和单引号

select * from table where id=2 (不规范)

select * from ·table· where ·id·=’2’ (规范)

3、正确的使用 $_post $_get $_session 等接受参数,并加以过滤

4、提高数据库教程命名技巧,对于一些重要的字段可根据程序特点命名

5、对于常用方法加以封装,避免直接暴露sql语句

 

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn