Search code examples
phpcookiessetcookie

Cookie expiration is browser specific or server specific?


I am setting a a cookie with an expiration time by

mktime(24,0,0).

My question is simple. If browsers timezone is different , will cookie follow the server's timezone to expire or browser's timezone ?


Solution

  • The Set-Cookie header has timezone information as part of the expires datetime so the user agent knows when it should expire.

    Set-Cookie: sessionToken=abc123; Expires=Wed, 09 Jun 2021 10:18:14 GMT

    From the php docs for setcookie

    expire

    ...

    Note: You may notice the expire parameter takes on a Unix timestamp, as opposed to the date format Wdy, DD-Mon-YYYY HH:MM:SS GMT, this is because PHP does this conversion internally.