phpcookie类
Posted layfork
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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类的主要内容,如果未能解决你的问题,请参考以下文章
如何通过单击片段内的线性布局从片段类开始新活动?下面是我的代码,但这不起作用
elasticsearch代码片段,及工具类SearchEsUtil.java
Android 逆向类加载器 ClassLoader ( 类加载器源码简介 | BaseDexClassLoader | DexClassLoader | PathClassLoader )(代码片段