PHP cookie time format not working

I have these two cookies, and they work, but only if the cookies last for 5 hours or more, nothing lower. If I set the cookie expiration to 0, it will also work, but I need the cookie to expire after 2 hours. It works in firefox when I set a cookie for up to 2 hours, but not in Chrome or IE.

I see that the browser (Chrome) receives a cookie if it expires in five hours or more. or if the expiration is 0. What am I doing wrong?

setcookie('expire', 'test', time() + 7200, "/");

I do not know why the time function does not work, so my cookie expires in two hours.

Any help would be greatly appreciated.

+3
source share
2 answers

, ? , UTC, . , phpdate C R:

$date = new Datetime('+2 hours');
setcookie('expire', 'test', $date->format('C'), "/");

, cookie:

setcookie('expire', 'test', $date->format(DateTime::COOKIE), "/");

, . , , .

+7

, , . , , .

0

All Articles