What is the client side time zone cookie?

I need to set a cookie that expires in 1 hour using the PHP setcookie function. The time zone on my server is set to GMT. How to set cookie expiration date so that it works in different browser hours?

+8
timezone php cookies
source share
4 answers

Nearby, as I can say, it does not matter what client time is. PHP sets expiration time based on unix timecode. Any changes at this time should be on the server.

Here is an excerpt from the PHP manual for setcookie ():

expires:

The time that the cookie expires. This is a Unix timestamp, so this is the number of seconds since the era. In other words, you will most likely set this using the time () function plus the number of seconds before you want it to expire. Or you can use mktime (). Time () + 60 * 60 * 24 * 30 the cookie expires in 30 days. If set to 0 or omitted, the cookie expires at the end of the session (when the browser closes).

+7
source share

PHP's setcookie () function accepts an integer corresponding to a Unix timestamp value. If your cookie should have 1 hour of life, you can simply use time () + 3600 for this value. PHP will then create a cookie with the expiration of time, for example, "expires = Fri, 3 Aug 2001 20:47:11 UTC". It is in UTC (GMT) format, so you do not need to worry about the time zone of the client browser.

+5
source share

You can try with getTimeZone and setTimeZone Take a look here

Also strtotime seems suitable for getting the correct date and time format, then you can use gmdate to convert

0
source share

Suppose you use a set cookie.

Maybe I'm wrong, but I think:

You specify the expire parameter as a Unix timestamp, and you calculate the timestamp as β€œin an hour,” so you want the cookie to expire in an hour. Therefore, you do not need to consider the time zone, since the unix timestamp is unique.

Then the browser’s task is to translate the unix timestamp into a date based on the settings of the browser (language, language, etc.).

0
source share

All Articles