zoukankan      html  css  js  c++  java
  • FuelPHP 系列(五) ------ Security 防御

    项目中难免会有 form 提交,对用户输入的所有信息进行过滤,可以避免 XSS 攻击,防止 SQL 注入。

    一、设置配置信息

    首先在 config.php 文件中,对 security 相关信息进行设置,

    二、常用方法

    1、clean($value, $filters = null)

    //将 $text 通过过滤器 filters 进行过滤
    $text = "<script>alert(111);</script>";
    $filters = array('strip_tags', 'htmlentities', '\cleaners\soap::clean');
    $text = Security::clean($text, $filters);
    
    
    //输出结果如下:
    string(7) "t(111);" 

    2、strip_tags($value) 去除 HTML、PHP 标签

    //去除 $text 字符串中的 p 标签
    $text = '<p>Test paragraph.</p>';
    $text = Security::strip_tags($text);
    
    //输出结果如下:
    string(15) "Test paragraph." 

    3、xss_clean($value, array $options = array())

    //去除 $text 中的标签,保留 <br/>
    $text = '<script>alert("XSS attack!")<br/></script>';
    $text = Security::xss_clean($text, array('br'));
    
    
    //输出结果为:
    string(39) "alert("XSS attack!")
    " 

    4、htmlentities($value, $flags = null, $encoding = null, $double_encode = null)

     //和 php 同名函数效果相同
    $text = '<p>Test paragraph.</p>';
    $text = Security::htmlentities($text);

    5、e($string)

      e 函数是 Security::htmlentities. 函数的别名,效果相同

    三、在模板中的用法

  • 相关阅读:
    Python 反射
    Python 类描述符-Descriptor
    Python 面向对象三大特性-多态
    Python 面向对象三大特性-继承
    Python 面向对象三大特性-封装
    面向对象编程
    python之mysqldb模块安装
    Redis应用-分布式锁
    ide phpStorm使用git的命令行工具
    mysql中用命令行复制表结构(数据)
  • 原文地址:https://www.cnblogs.com/rendd/p/9291103.html
Copyright © 2011-2022 走看看