cookie 问题 [ 新手入门 ]
$cookie = new CHttpCookie('Sid','this is my cookie');
$cookie->expire = time()+60*60*24*30; //有限期30天
$cookie->path = $this->TisWebsiteUrl;
Yii::app()->request->cookies['mycookie']=$cookie;
单个是这样写,多个怎么写
setcookie("Ud", $_GET['Ud'], time()+30*24*3600, "/", $this->TisWebsiteUrl);
setcookie("Pd", $_GET['Pd'], time()+30*24*3600, "/", $this->TisWebsiteUrl);
比如下边这样的,
共 10 条回复
-
$cookie = new CHttpCookie('Ud',$_GET['Ud']); $cookie->expire = time()+60*60*24*30; //有限期30天 $cookie->path = $this->TisWebsiteUrl; //有限期30天 $cookie = new CHttpCookie('Pd',$_GET['Pd']); $cookie->expire = time()+60*60*24*30; //有限期30天 $cookie->path = $this->TisWebsiteUrl; //有限期30天 $cookie = new CHttpCookie('Sid',$_GET['Sid']); $cookie->expire = time()+60*60*24*30; //有限期30天 $cookie->path = $this->TisWebsiteUrl; //有限期30天 $cookie = new CHttpCookie('Ukey',$_GET['Ukey']); $cookie->expire = time()+60*60*24*30; //有限期30天 $cookie->path = $this->TisWebsiteUrl; //有限期30天 Yii::app()->request->cookies['mycookie']=$cookie;
这样写也不对
-
报什么错误?
参考一下这个:
http://www.yiiframework.com/doc/api/1.1/CHttpCookie
设置cookie:$cookie = new CHttpCookie('mycookie','this is my cookie'); $cookie->expire = time()+60*60*24*30; //有限期30天 Yii::app()->request->cookies['mycookie']=$cookie; 读取cookie:$cookie = Yii::app()->request->getCookies(); echo $cookie['mycookie']->value; 销毁cookie:$cookie = Yii::app()->request->getCookies(); unset($cookie[$name]);
-
$cookieUd = new CHttpCookie('Ud',$_GET['Ud'],'Pd'.$_GET['Pd'],'Sid'.$_GET['Sid'],'Ukey'.$_GET['Ukey']); $cookieUd->expire = time()+60*60*24*30; //有限期30天 $cookieUd->path = $this->TisWebsiteUrl; //有限期30天 // print_r($cookie);exit; Yii::app()->request->cookies['Ud']=$cookieUd;
这样,
$cookiePd = new CHttpCookie('Pd'.$_GET['Pd']); $cookiePd->expire = time()+60*60*24*30; //有限期30天 $cookiePd->path = $this->TisWebsiteUrl; //有限期30天 // print_r($cookie);exit; Yii::app()->request->cookies['Pd']=$cookiePd; $cookieSid = new CHttpCookie('Sid'.$_GET['Sid']); $cookieSid->expire = time()+60*60*24*30; //有限期30天 $cookieSid->path = $this->TisWebsiteUrl; //有限期30天 // print_r($cookie);exit; Yii::app()->request->cookies['Sid']=$cookieSid; $cookieUkey = new CHttpCookie('Ukey'.$_GET['Ukey']); $cookieUkey->expire = time()+60*60*24*30; //有限期30天 $cookieUkey->path = $this->TisWebsiteUrl; //有限期30天 // print_r($cookie);exit; Yii::app()->request->cookies['Ukey']=$cookieUkey;
下边这样,全不行,有没有好的方法,可以传多个
-
$cookieUd = new CHttpCookie('Ud',$_GET['Ud']); $cookieUd->expire = time()+60*60*24*30; //有限期30天 $cookieUd->path = $this->TisWebsiteUrl; //有限期30天 // print_r($cookie);exit; Yii::app()->request->cookies['Ud']=$cookieUd; $cookiePd = new CHttpCookie('Pd',$_GET['Pd']); $cookiePd->expire = time()+60*60*24*30; //有限期30天 $cookiePd->path = $this->TisWebsiteUrl; //有限期30天 // print_r($cookie);exit; Yii::app()->request->cookies['Pd']=$cookiePd; $cookieSid = new CHttpCookie('Sid',$_GET['Sid']); $cookieSid->expire = time()+60*60*24*30; //有限期30天 $cookieSid->path = $this->TisWebsiteUrl; //有限期30天 // print_r($cookie);exit; Yii::app()->request->cookies['Sid']=$cookieSid; $cookieUkey = new CHttpCookie('Ukey',$_GET['Ukey']); $cookieUkey->expire = time()+60*60*24*30; //有限期30天 $cookieUkey->path = $this->TisWebsiteUrl; //有限期30天 // print_r($cookie);exit; Yii::app()->request->cookies['Ukey']=$cookieUkey;
这样可以了,谢谢
mab741
注册时间:2012-07-30
最后登录:1970-01-01
在线时长:0小时0分
最后登录:1970-01-01
在线时长:0小时0分
- 粉丝0
- 金钱145
- 威望0
- 积分145