Problem Reading Jquery Cookie In Yii

I am using the jquery cookie plugin that is included in Yii.

In my javascript file, I am creating a new cookie this way:


$.cookie('test',12, { expires: 7, path: '/'});

When I reload the page, this cookie exists in


$_SERVER['HTTP_COOKIE']

but I cannot access it through


Yii::app()->request->cookies['test']

Am I doing something wrong? Thank you in advance.

I think it can be caused by enableCookieValidation.

http://www.yiiframework.com/doc/api/1.1/CCookieCollection#getCookies-detail

That’s right, I had cookie validation enabled. Once I removed it, the cookie appeared in yii variables!

So, either I will go on using $_COOKIE or I will disable validation. If you can tell me some way to create yii-validated cookies through jquery cookie, let me know.

Thank you very much!

I think you have to send an ajax request to set a “yii-validated” cookie, because only Yii knows the private key used to generate cookie hash. I guess you don’t want to keep it in javascript code :)