语法
|
set_cookie($name[, $value = ''[, $expire = ''[, $domain = ''[, $path = '/'[, $prefix = ''[, $secure = FALSE[, $httponly = FALSE ]]]]]]]]]) |
Parameters
|
$name (mixed)-此函数可用的所有参数的 Cookie 名称或关联数组 $value (string)-Cookie 值 $expire (int)-到期前的秒数 $domain (string)-Cookie 域(通常为:.yourdomain.com) $path (string)-Cookie 路径 $prefix (string)-Cookie 名称前缀 $secure (bool)-是否仅通过 HTTPS 发送 cookie $httponly (bool)-是否对 JavaScript 隐藏 cookie |
Return Type
|
void |
语法
|
get_cookie($index[, $xss_clean = NULL]]) |
Parameters
|
$index (string)-Cookie 名称 $xss_clean (bool)-是否对返回值应用 XSS 过滤 |
Returns
|
cookie 值或 NULL(如果未找到) |
Return Type
|
mixed |
语法
|
delete_cookie($name[, $domain = ''[, $path = '/'[, $prefix = '']]]]) |
Parameters
|
$name (string)-Cookie 名称 $domain (string)-Cookie 域(通常为:.yourdomain.com) $path (string)-Cookie 路径 $prefix (string)-Cookie 名称前缀 |
Return Type
|
void |
<?php class Cookie_controller extends CI_Controller { function __construct() { parent::__construct(); $this->load->helper(array('cookie', 'url')); } public function index() { set_cookie('cookie_name','cookie_value','3600'); $this->load->view('Cookie_view'); } public function display_cookie() { echo get_cookie('cookie_name'); $this->load->view('Cookie_view'); } public function deletecookie() { delete_cookie('cookie_name'); redirect('cookie/display'); } } ?>
<!DOCTYPE html> <html lang = "en"> <head> <meta charset = "utf-8"> <title>CodeIgniter View Example</title> </head> <body> <a href = 'display'>Click Here</a> to view the cookie.<br> <a href = 'delete'>Click Here</a> to delete the cookie. </body> </html>
$route['cookie'] = "Cookie_controller"; $route['cookie/display'] = "Cookie_controller/display_cookie"; $route['cookie/delete'] = "Cookie_controller/deletecookie";
http://yoursite.com/index.php/cookie