喇叭客 发表于 2015-7-15 20:19:03

input 类cookie的问题

本帖最后由 Closer 于 2015-7-16 13:52 编辑

在默认配置里面,如果cookie_prefix为空的话,我们set_cookie之后,在cookie是没有问题的;但如果cookie_prefix有值的话,取出的值为空的?
按照官方的代码,在_fetch_from_array之前,不是得判断一下是否有前缀设置的情况吗?

下面官方代码:
/**
* Fetch an item from the COOKIE array
*
* @param      mixed      $index                Index for item to be fetched from $_COOKIE
* @param      bool      $xss_clean      Whether to apply XSS filtering
* @return      mixed
*/

public function cookie($index = NULL, $xss_clean = NULL) {
    return $this->_fetch_from_array($_COOKIE, $index, $xss_clean);
}

/**
* Set cookie
*
* Accepts an arbitrary number of parameters (up to 7) or an associative
* array in the first parameter containing all the values.
*
* @param      string|mixed[]      $name                Cookie name or an array containing parameters
* @param      string                $value                Cookie value
* @param      int                $expire                Cookie expiration time in seconds
* @param      string                $domain                Cookie domain (e.g.: '.yourdomain.com')
* @param      string                $path                Cookie path (default: '/')
* @param      string                $prefix                Cookie name prefix
* @param      bool                $secure                Whether to only transfer cookies via SSL
* @param      bool                $httponly      Whether to only makes the cookie accessible via HTTP (no javascript)
* @return      void
*/

public function set_cookie($name, $value = '', $expire = '', $domain = '', $path = '/', $prefix = '', $secure = FALSE, $httponly = FALSE) {
    if (is_array($name)){
      // always leave 'name' in last place, as the loop will break otherwise, due to $$item
      foreach (array('value', 'expire', 'domain', 'path', 'prefix', 'secure', 'httponly', 'name') as $item){
            if (isset($name[$item])){
                $$item = $name[$item];
            }
      }
    }
   
    if ($prefix === '' && config_item('cookie_prefix') !== ''){
      $prefix = config_item('cookie_prefix');
    }
   
    if ($domain == '' && config_item('cookie_domain') != ''){
      $domain = config_item('cookie_domain');
    }
   
    if ($path === '/' && config_item('cookie_path') !== '/'){
      $path = config_item('cookie_path');
    }
   
    if ($secure === FALSE && config_item('cookie_secure') === TRUE){
      $secure = config_item('cookie_secure');
    }
   
    if ($httponly === FALSE && config_item('cookie_httponly') !== FALSE){
      $httponly = config_item('cookie_httponly');
    }
   
   
    if ( ! is_numeric($expire)){
      $expire = time() - 86500;
    }else{
      $expire = ($expire > 0) ? time() + $expire : 0;
    }
   
    setcookie($prefix.$name, $value, $expire, $path, $domain, $secure, $httponly);
}
页: [1]
查看完整版本: input 类cookie的问题