mab741 2012-08-09 09:16:08 3679次浏览 10条回复 0 0 0
$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);

比如下边这样的,

  • 回复于 2012-08-09 10:25 举报
    $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;
    

    这样写也不对

  • 回复于 2012-08-09 10:42 举报

    报什么错误?
    参考一下这个:
    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]);
    
  • 回复于 2012-08-09 11:04 举报

    晕,兄弟看清楚问题,现在是要多个name,

  • 回复于 2012-08-09 11:05 举报

    第二楼的内容,只可以写入最后一个,别的写入不了

  • 回复于 2012-08-09 14:45 举报

    不要都用$cookie这一个变量名,多弄几个,好操作前两个。

  • 回复于 2012-08-09 14:46 举报

    点一下“回复”,这样我才能在“提醒”里看到回复。

  • 回复于 2012-08-10 15:53 举报
    $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;
    

    下边这样,全不行,有没有好的方法,可以传多个

  • 回复于 2012-08-10 16:03 举报

    哪儿不行呢?报什么错误呢?

  • 回复于 2012-08-10 16:04 举报
    $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;
    

    这样可以了,谢谢

  • 回复于 2012-08-10 18:44 举报

    这是哪儿错了呢???

您需要登录后才可以回复。登录 | 立即注册