Home  >  Article  >  php教程  >  PHP CodeIgniter学习笔记详解

PHP CodeIgniter学习笔记详解

WBOY
WBOYOriginal
2016-05-25 16:48:251198browse

今天做的是个简单的表明表页面,前端我用的是Bootstrap.没办法,自己不懂美工,也只有用别人的工具.BS真的很漂亮,而且插件丰富,不愧是twitter工程师弄出来的东西.

好的东西大家都喜欢,但是它对IE6-9的兼容几乎是0.大家也懂的,国外基本是不使用这几款浏览器了,不过在中国,IE依然占有很高的市场份额.所以,有人开发了一款叫做BSIE的Bootstrap插件,美其名曰鄙视IE,使用方法也相当简单,好像有点跑题,后端我用的是CodeIgniter,它是基于PHP的开源框架.CI是今天的正题,因为CI对于数据的过滤函数只有xss_clean(),(不知道是不是自己才疏学浅,总之没有找到其他的过滤函数)而今天的项目涉及到接收用户数据,然后提交数据库的操作.没有针对SQL语句的过滤,使得这一操作变得很危险.有点蛋蛋的忧桑,我想到的方法是改写CI的xss_clean()函数,使之具备过滤SQL注入语句的功能;一来改起来方便,二来过滤数据的时候不用嵌套两个函数.说干就干,在CI/system/core/目录下找到secure.php文件,找到xss_clean()函数的申明位置,在最后加上这么一段东西.

PHP实例代码如下:

$str = str_replace("_","x",$str);      
$str = str_replace("%","x",$str);      
$str = str_replace(""","x",$str);      
$str = str_replace("'","x",$str);      
$str = str_replace("select","x",$str);      
$str = str_replace("update","x",$str);      
$str = str_replace("insert","x",$str);     
$str = str_replace("set","x",$str);     
$str = str_replace("where","x",$str);     
$str = str_replace("from","x",$str);     
$str = str_replace("alert","x",$str);      
$str = str_replace("like","x",$str);     
return $str;

这样差不多能避免一般的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