码迷,mamicode.com
首页 > Web开发 > 详细

php hash防止表单

时间:2017-07-12 16:13:29      阅读:236      评论:0      收藏:0      [点我收藏+]

标签:blog   storm   pos   create   hash   func   orm   ons   dex   

<?php

/**
 * Created by PhpStorm.
 * User: brady
 * Desc:
 * Date: 2017/7/12
 * Time: 15:01
 */
class test extends MY_Controller
{
    public function __construct()
    {
        parent::__construct();
    }

    public function index()
    {
        //防csrf攻击
        $hash = md5(uniqid(rand(), TRUE));
        set_cookie("__hash__", $hash, 3600, get_public_domain());
        $this->_viewData[‘__hash__‘] = $hash;
        parent::index();
    }

    public function do_submit()
    {
        $data = $this->input->post();
        if(empty($data[‘__hash__‘])){
            echo "hacker";
        }
        echo $cookie_hash = get_cookie(‘__hash__‘);

        if($cookie_hash === $data[‘__hash__‘]) {
            echo "验证通过";
            delete_cookie("__hash__",get_public_domain());
            dump($_COOKIE);
        } else {
            echo "hacker";
        }

    }
}

  

php hash防止表单

标签:blog   storm   pos   create   hash   func   orm   ons   dex   

原文地址:http://www.cnblogs.com/php-linux/p/7155909.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!