Yii’s common operations on cookies include the following:
1. Set cookies:
$cookie = new CHttpCookie('mycookie','this is my cookie'); $cookie->expire = time()+60*60*24*30; //有限期30天 Yii::app()->request->cookies['mycookie']=$cookie;
2. Read cookie:
$cookie = Yii::app()->request->getCookies(); echo $cookie['mycookie']->value;
3. Destroy cookies:
$cookie = Yii::app()->request->getCookies(); unset($cookie[$name]);
blog.163.com/...56185/
/**Storage Cookies: Two parameters, one is the name of the cookie, the other is the value*/
function SetCookie(name,value){
var Days = 30; //This cookie will be Save for 30 days
var exp = new Date();//new Date("December 31, 9998");
exp.setTime(exp.getTime() + Days*24*60*60*1000) ;
document.cookie = name + "="+ escape (value) + ";expires="+exp.toGMTString();
}
/**Get cookies function*/
function getCookie(name){
var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));
if (arr != null) return unescape(arr[2]); return null;
}
/**Delete cookie*/
function delCookie(name){
var exp = new Date( );
exp.setTime(exp.getTime() - 1);
var cval=getCookie(name);
if(cval!=null) document.cookie= name + "="+cval+ ";expires="+exp.toGMTString();
}
You can operate wherever you want