码迷,mamicode.com
首页 > 其他好文 > 详细

CI - Set CSRF Hash and Cookie

时间:2016-07-12 13:41:18      阅读:202      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!