|Cookies, the new frontier.|
Newby requesting help for a banal issue.
I’m a newbie in server side (perl) and I just found out how to deal with cookies. Let me tell you “I’ve discover the wet gun powder”. My new knowledge is great for applications that I was unable to do till now. To be honest, not till now, still having problems.
I can create the cookies and set it in client side, but IE7 do not receive them or does not allow the cookies to be reached. Everything is fine for Mozilla and FireFox about receiving the cookies, even for IE6 cookies are fine, but it doesn’t work with IE7. Beside, the “expire” parameter only works for Mozilla. Firefox and both IE I’ve tried do not seam to respect that. I do not know if this expiration issue is due to the browser or the script, that’s why my help request.
My script to set a cookie is:
$cgi->header( -cookie => new CGI::Cookie(-name => 'MyCookie',
-value => 'This_value',
-expires => '+1h',
-path => ‘\’,
-domain => 'something.com'
Can somebody, please, set some light over this issue?
Why cookies can not be set in IE7 and why some browser do not respect cookies life time?
That code doesn't quite look right, have you missed a line or 2 out? And you seem to have gained a }.
my $cgi = new CGI;
print $cgi -> header(
-cookie => $cgi -> cookie(
-name => "MyCookie",
-value => "Something",
-path => "/",
-expires => '+1h',
ok, a few notes....
The slash in your path is the wrong way around. Setting a root path is handy so you can use the cookies across the whole site, like with a session cookie.
No need to set the domain really, unless you want the cookie to traverse subdomains which is quite unusual.
The expires +1h is translated by the CGI module into a UTC date string, like "Thu, 17 Sep 2008 17:39:11 UTC". This is what the browser receives. Although I found (with IE, not tested in other browsers), that although the expire time had passed, as long as you hadn't navigated away from the page the cookie was still sent to the server. Best practise is to assign a unique ID, and track it's time on the server, rather than relying on the client to expire.
Now, about cross browser cookies....
There's no such thing. Cookies happen in the HTTP header part of the communication. All browsers and servers handle cookies in the same way.
Hope this helps!
You are very right about the mistake and the missing line
my $cgi = new CGI;
The gained } is due to the fact that my cookie is inside an “if” and I’ve copy it from my script and did not noticed that the } was coming along. The same goes to the line above, it is outside the “if” and it was not copied, but actually it is there for the script to function.
I believe that I’ve found the reason why the IE7 was not accepting the cookie and Mozilla was.
The IE7 and Mozilla are in my PC that has a clock set to (example) 15:15 and the server have the clock at 14:00. There is a difference of 1h 15m.
Even with time being converted to UTC there still a gap of 1h 15m.
When I set a cookie to expire 1 h after in IE7, the cookie can not be found because it already expired. Looks like IE7 regards the local system time to check cookie expire time. So the cookie is expired at the time it is set on the client.
With Mozilla the behaviour is different even in the same PC and therefore with the same system local time that IE7, Mozilla does not pay attention to System clock and respect the server time and 1 hour is required to expire. 1 hour is the server clock.
This is the conclusion I got after a lot of research. After synchronise both clocks, everything was the way I plan it.
Does this make any cense to you?
Have somebody lived the same experience that I and got to the same conclusion?
|When I set a cookie to expire 1 h after in IE7, the cookie can not be found because it already expired |
Yeah that would kill it every time.
Actually there's no way to delete a cookie, the approved way is to give it an expire string in the past!
Although it's very strange that it worked for Mozilla.