首页 > 其他 > 详细

CI - Set CSRF Hash and Cookie

时间:2016-07-12 13:39:34      阅读:243      评论:0      收藏:0      [点我收藏+]
/**
     * Set CSRF Hash and Cookie
     *
     * @return    string
     */
    protected function _csrf_set_hash()
    {
        if ($this->_csrf_hash === NULL)
        {
            // If the cookie exists we will use its value.
            // We don‘t necessarily want to regenerate it with
            // each page load since a page could contain embedded
            // sub-pages causing this feature to fail
            if (isset($_COOKIE[$this->_csrf_cookie_name]) && is_string($_COOKIE[$this->_csrf_cookie_name])
                && preg_match(‘#^[0-9a-f]{32}$#iS‘, $_COOKIE[$this->_csrf_cookie_name]) === 1)
            {
                return $this->_csrf_hash = $_COOKIE[$this->_csrf_cookie_name];
            }

            $rand = $this->get_random_bytes(16);
            $this->_csrf_hash = ($rand === FALSE)
                ? md5(uniqid(mt_rand(), TRUE))
                : bin2hex($rand);
        }

        return $this->_csrf_hash;
    }

 

CI - Set CSRF Hash and Cookie

原文:http://www.cnblogs.com/bravehunter/p/5663043.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!