This code should remove the old cookie and set replace with a new one but seems to just create a new cookie of the same name. So I end up with duplicates.
Any idea why?
// the name of the cookie $siteIDCookieName = Yii::app()->user->id."viewersiteid"; // remove the old cookie unset(Yii::app()->request->cookies[$siteIDCookieName]); // create a new cookie $cookie = new CHttpCookie($siteIDCookieName,$_POST['SiteInfo']['SiteInfoID']); // set expiry time $cookie->expire = time()+60*60*24*365; // assign the new cookie to the cookies collection Yii::app()->request->cookies[$siteIDCookieName] = $cookie; // set the siteid var $siteID = Yii::app()->request->cookies[$siteIDCookieName]->value; // set the siteid user state Yii::app()->user->setState('siteid', $siteID);