zoukankan      html  css  js  c++  java
  • 开始学习CI框架

    1.自己的类
    $this->load->library('someclass');

    2.使用codeigniter类库 system/libraries
    $this->load->library('form_validation');
    $this->load->library(array('email','table'));

    3.辅助函数 system/helpers application/helpers
    CodeIgniter 将会先在 application/helpers 寻找对应的辅助函数文件,如果目录不存在或者目录下没有对应的辅助函数文件,
    CI 才会载入 system/helpers 下的辅助函数文件。


    url helpers 创建链接
    form helpers 创建表单
    text helpers 格式化输出方式
    cookie helpers 设置和读取COOKIE
    file helpers 处理文件

    $this->load-helper('name');
    $this->load->helper(array('helper1','helper2','helper3'));

    扩展helpers application/helpers/MY_array.php

    4.公共函数
    system/core/common.php

    is_php('version_number')
    is_php() 判断正在使用的PHP的版本号是否高于你所提供的 version_number
    is_really_writable('path/to/file')
    config_item('item_key') 取得单个配置信息
    show_error('message'), show_404('page'), log_message('level', 'message') 允许你手动设置服务器状态头(header)。
    set_status_header(code, 'text'); 这个函数能防止在ASCII字符之间插入空字符,如Java\0script
    remove_invisible_characters($str)
    html_escape($mixed) 利用此功能可以方便的使用htmlspecialchars()函数。它接受字符串和数组。有助于防止跨站脚本攻击(XSS)。


    5.URI路由

    application/config/routes.php


    6.缓存

    启用缓存
    $this->output->cache(n);

    其中 n 是你希望缓存更新的 分钟 数。可以使用 m/60 来精确到秒,例如 1/60 ,则是精确到 1秒

    7.安全
    在接收任何数据到你的程序之前,不管是表单提交的 POST 数据、COOKIE 数据、URI 数据、XML-RPC 数据、还是 SERVER 数组中的数据
    ,我们都推荐你实践下面的三个步骤:

    a.过滤不良数据.
    b.验证数据以确保符合正确的类型, 长度, 大小等. (有时这一步骤也可取代第一步骤)
    c.在提交数据到你的数据库之前将其转换.
    CodeIgniter 提供了下列函数以辅助这个过程:
    xss过滤
    $data=$this->security->xss_clean($data);

    if ($this->security->xss_clean($file, TRUE) === FALSE)
    {
    // file failed the XSS test
    }

    $filename = $this->security->sanitize_filename($this->input->post('filename'));
    当接受用户所输入的文件名时, 最好是对它们进行一下“消毒”, 这样能避免目录被遍历以及其它安全相关的问题. 要完成这项
    工作, 请使用安全类中的 sanitize_filename() 方法.

    $config['global_xss_filtering']= TRUE;过滤器能自动过滤所有被访问到的POST或者COOKIE数据
    $config['csrf_protection']=TRUE; 跨站请求伪造


    验证数据
    插入数据库之前转义所有数据

  • 相关阅读:
    3.24 每日一题题解
    3.23 每日一题题解
    3.22 每日一题题解
    【POJ1222】EXTENDED LIGHTS OUT
    【BZOJ1013】球形空间产生器sphere
    【hdu4135】【hdu2841】【hdu1695】一类通过容斥定理求区间互质的方法
    【HDU5862】Counting Intersections
    【HDU1542】Atlantis
    【自定义】抢妹子大作战
    【HDU5361】In Touch
  • 原文地址:https://www.cnblogs.com/suihui/p/2621765.html
Copyright © 2011-2022 走看看