So I am creating cookies using Perl's CGI module, and I do it as so:
my $cookie = CGI::Cookie->new(-name => "$name",
-value => "$val",
-expires => "$expiration_date",
-path => $cookie_path,
-secure => 0
);
print "Set-Cookie: $cookie\n";
And the cookie is set in the browser, the only issue is that the time does not match up with the expiration date I put. For example, if I put +1d for expiration date, it really does something like +1d - several hours. I checked my system time to see if that was the issue, but my system time is right. Then I printed out the cookie and I got this:
Actual Time of cookie creation: 6/4/2012 12:10:02 PM
COOKIE: session_id=534fec49c864d8cf0325779b0921b6be1338829802484; path=/; expires=Tue, 05-Jun-2012 17:10:02 GMT
The strage thing above is that I record the actual time of cookie creation with perl's 'localtime(time())' function, but it records a different time than what my date command puts out (so not the actual current time)! And then the expiration time on the cookie is actually correct, but it's in the wrong time zone.
So my server is in the eastern timezone when I run the date command:
Mon Jun 4 12:05:12 EST 2012
However, the cookie is being set with GMT as the timezone, and I think this is the issue. Is there another time I should be setting on the server besides just date? I'm running on CentOS 5 if that helps at all. Thanks!
Those times are actually equivalent (12:00 EST is 17:00 GMT). Note that cookies are required, by the specification, to specify the expiry time in GMT. Your browser, in turn, is required to automatically convert the time zone back.
In so many words: everything is happening as it should.
but it records a different time than what my date command puts out
That's not true.
Tue, 05-Jun-2012 17:10:02 GMT
and
Tue, 05-Jun-2012 12:10:02 EST
are different representations of the exact same time. There's no problem. There would be a problem if you had gotten
Tue, 05-Jun-2012 17:10:02 EST
or
Tue, 05-Jun-2012 12:10:02 GMT
But you didn't.
GMT is used because "EST" is ambiguous — there's a time zone in Australia with the same name — and because only one time zone needs to be known instead of all of them if everyone uses GMT.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With