Suppose I create a cookie that expires at creation time the following example I use yii
$data_cookie = new CHttpCookie('_MD2', $data);
$data_cookie->expire = time();
Yii::app()->request->cookies['_MD2'] = $data_cookie;
now I tried to get it's value using the following code
yii::app()->request->cookies['_MD2']->value
but nothing I obtain when i change it's expiry date i gain it's value
so is that true not to obtain a cookie value when it expires even if browser is not closed ?
note : I tested it in mozilla latest release
If you set an expiration time on a cookie, it expires at that time, not when the browser as closed. The browser isn't going to send you back an expired cookie, even if it was just set immediately before.
Setting an expiration of now (or in the past) is actually a common method to delete a cookie that already exists with the same name.
Yes, it's a good practice to check expiry date. Especially if you have a high volume website. But cookie can be deleted with an expiry date too.
If a cookie has expired... it's expired. It gets thrown out, not sent to your server. Set an expiration in the future if you actually want to get the cookie back.