yii操作cookie方法示例
来源: 互联网 发布时间:2014-08-30
本文导语: yii对cookie的操作常用方法: 1,设置cookie: 代码示例: $cookie = new CHttpCookie('mycookie','this is my cookie'); $cookie->expire = time()+60*60*24*30; //有限期30天 Yii::app()->request->cookies['mycookie']=$cookie; 2,读取cookie: 代码示例: $cookie = Yii::app()...
yii对cookie的操作常用方法:
1,设置cookie:
代码示例:
$cookie = new CHttpCookie('mycookie','this is my cookie');
$cookie->expire = time()+60*60*24*30; //有限期30天
Yii::app()->request->cookies['mycookie']=$cookie;
$cookie->expire = time()+60*60*24*30; //有限期30天
Yii::app()->request->cookies['mycookie']=$cookie;
2,读取cookie:
代码示例:
$cookie = Yii::app()->request->getCookies();
echo $cookie['mycookie']->value;
echo $cookie['mycookie']->value;
3,销毁cookie:
代码示例:
$cookie = Yii::app()->request->getCookies();
unset($cookie[$name]);
unset($cookie[$name]);
以上就是yii框架中最基础的cookie操作方法,封装的很好,使用起来很简单。