设置Cookie:
?
1
2
3
4
5
6 //首先新建cookie
$cookie=newCHttpCookie('qblog','test cookie');
//定义cookie的有效期
$cookie->expire = time()+60*60*24*30; //有限期30天
//把cookie写入cookies使其生效
Yii::app()->request->cookies['qblog']=$cookie;
读取Cookie:
?
1
2 $cookie= Yii::app()->request->getCookies();
echo$cookie['qblog']->value;
销毁Cookie:
?
1
2 $cookie= Yii::app()->request->getCookies();
unset($cookie['qblog']);