企业🤖AI Agent构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
# Cookie 辅助函数 Cookie 辅助函数文件包含了一些帮助你处理 Cookie 的函数。 [TOC=2,3] ## [加载辅助函数](http://codeigniter.org.cn/user_guide/helpers/cookie_helper.html#id3) 该辅助函数通过下面的代码加载: ~~~ $this->load->helper('cookie'); ~~~ ## [可用函数](http://codeigniter.org.cn/user_guide/helpers/cookie_helper.html#id4) 该辅助函数有下列可用函数: set_cookie($name[, $value = ''[, $expire = ''[, $domain = ''[, $path = '/'[, $prefix = ''[, $secure = FALSE[, $httponly = FALSE]]]]]]]]) 参数: * **$name** (mixed) -- Cookie name or associative array of all of the parameters available to this function * **$value** (string) -- Cookie value * **$expire** (int) -- Number of seconds until expiration * **$domain** (string) -- Cookie domain (usually: .yourdomain.com) * **$path** (string) -- Cookie path * **$prefix** (string) -- Cookie name prefix * **$secure** (bool) -- Whether to only send the cookie through HTTPS * **$httponly** (bool) -- Whether to hide the cookie from JavaScript 返回类型: void 该辅助函数提供给你一种更友好的语法来设置浏览器 Cookie,参考 [输入类](http://codeigniter.org.cn/user_guide/libraries/input.html) 获取它的详细用法,另外,它是 CI_Input::set_cookie() 函数的别名。 get_cookie($index[, $xss_clean = NULL]]) 参数: * **$index** (string) -- Cookie name * **$xss_clean** (bool) -- Whether to apply XSS filtering to the returned value 返回: The cookie value or NULL if not found 返回类型: mixed 该辅助函数提供给你一种更友好的语法来获取浏览器 Cookie,参考 [输入类](http://codeigniter.org.cn/user_guide/libraries/input.html) 获取它的详细用法,同时,这个函数 和 CI_Input::cookie() 函数非常类似,只是它会根据配置文件 application/config/config.php 中的 $config['cookie_prefix'] 参数 来作为 Cookie 的前缀。 delete_cookie($name[, $domain = ''[, $path = '/'[, $prefix = '']]]]) 参数: * **$name** (string) -- Cookie name * **$domain** (string) -- Cookie domain (usually: .yourdomain.com) * **$path** (string) -- Cookie path * **$prefix** (string) -- Cookie name prefix 返回类型: void 删除一条 Cookie,只需要传入 Cookie 名即可,也可以设置路径或其他参数 来删除特定 Cookie。 ~~~ delete_cookie('name'); ~~~ 这个函数和 set_cookie() 比较类似,只是它并不提供 Cookie 的值和 过期时间等参数。第一个参数也可以是个数组,包含多个要删除的 Cookie 。 另外,你也可以像下面这样删除特定条件的 Cookie 。 ~~~ delete_cookie($name, $domain, $path, $prefix); ~~~