开发者

Get cookie expiration

Is it possible to read cookie expiration time with php ?开发者_如何学JAVA When I print_r($_COOKIE) it outputs:

Array
(
    [PHPSESSID] => 0afef6bac83a7db8abd9f87b76838d7f
    [userId] => 1232
    [userEmail] => user@email.com
    [firstName] => user
    [lastName] => user
)

So I think $_COOKIE don't have the expiration time, is it possible with some other function?


Only name and value are sent to the server so no other cookie data is available.

You can simply re-set the cookie if you want to extend its duration - that's just a few bytes more in the response so it doesn't matter at all.


no, there is no way.
Browser uses cookie parameters (path, expiration etc) only to determine to send a cookie or not, but none of these parameters being sent back to server.

don't think of a cookie as of a $_SESSON array member but as an HTTP header. That's always helps.


Or you can use the function time() on the value of the cookie, that way you need only one cookie and can retrieve data. The php code would look like this:

setCookie('cookiename', time(), time() + 86400);

That way, you'll have the cookie expiring in one day, and by retrieving it's value you can discover when it'll expire with something like this:

86400 - (time() - $_COOKIE['cookiename']);

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜