Get cookie expiration

前端 未结 3 452
别那么骄傲
别那么骄傲 2021-01-21 21:56

Is it possible to read cookie expiration time with php ? When I print_r($_COOKIE) it outputs:

Array
(
    [PHPSESSID] => 0afef6bac83a7db8abd9f87b         


        
3条回答
  •  攒了一身酷
    2021-01-21 22:37

    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']);

提交回复
热议问题