首页 > 代码库 > phpcookie类
phpcookie类
1.需求
写一个cookie类
2.例子
<?php class cookie{ private $COOKIE_PREFIX = ""; private $COOKIE_EXPIRE = ""; private $COOKIE_PATH = ""; private $COOKIE_DOMAIN = ""; public function __construct() { //这里要加载config并赋值cookie的相关参数 } public function set_prefix($prefix=‘‘) { $this->COOKIE_PREFIX=$prefix; } public function get_prefix() { return $this->COOKIE_PREFIX; } public function is_set_cookies($name) { return isset($_COOKIE[$this->COOKIE_PREFIX . $name]); } public function get_cookie($name) { //正式环境下,这里要解密cookie $value = $_COOKIE[$this->COOKIE_PREFIX . $name]; return $value; } public function set_cookie($name, $value, $expire = "", $PATH = "", $domain = "", $prefix = "") { if (empty($expire)) { $expire = $this->COOKIE_EXPIRE; } else { $expire = time()+$expire; } if (empty($path)) { $path = $this->COOKIE_PATH; } if (empty($domain)) { $domain = $this->COOKIE_DOMAIN; } if (empty($prefix)) { $prefix = $this->COOKIE_PREFIX; } //value要加密 setcookie($prefix . $name, $value, $expire, $path, $domain, NULL, true); $_COOKIE[$prefix . $name] = $value; } public function delete_cookie($name) { setcookie($name,‘‘,-1); $_COOKIE[$this->COOKIE_PREFIX . $name]=null; unset($_COOKIE[$this->COOKIE_PREFIX . $name]); } public function clear_all_cookie() { $_COOKIE =array(); unset($_COOKIE); } }
3.待完善部分
cookie的设置和读取要加密和解密的过程。
4.总结
无
phpcookie类
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。