Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Set Cookie Expiry Time (IE)

Status
Not open for further replies.

Extension

Programmer
Nov 3, 2004
311
CA
Hi,

I'm having some problems with Internet Explorer when trying to set a "expires" value.

Code:
my $cookie = $cgi->cookie(-name=>"id", -value=>$id, -domain=>"domain.com", max-age=>'60', -path=>'/cgi-bin/', -expires=>'+1m');

With Firefox everything is working fine. After 1 minute, the cookie expires but not with IE. I read that IE is now using max-age (in seconds) to define the expiry time. Even after populating the value, the cookie is still not expiring.

Any advice would be appreciated.
 
According to the book in front of me, -expires=>'+1m' means to expire after 1 month. It doesn't show any way to make it expire in increments of less than an hour.
 
I thought +1m was 1 minute and +1M was 1 month.
 
I've no idea, I'm just quoting from the Perl Black Book here on my desk. Maybe somebody else knows better.
 
I thought +1m was 1 minute and +1M was 1 month.
You are correct.

Quite possible the time on your computer is not correct forcing the cookie to automatically expire as it is set.

Try changing the time to +1h and see what happens.

M. Brooks
 
Also,

Code:
max-age=>'60',

This stands out to me. For one, CGI.pm usually has -'s at the start of hash arguments (compare "max-age" to "-expires" and "-name" and "-value", for example). And also, CGI.pm's arguments don't tend to have a - inside of them ("-content_type", for instance)

Try changing it to -max_age, or better yet, check the CGI docs to see what it says about its usage.

-------------
Kirsle.net | Kirsle's Programs and Projects
 

I think it's even more than the "expires" time because when I close the browser and I run the script again, the cookie are still active.

Everything is working perfectly with Firefox.

Is IE handling the cookies in a different way; I am suppose to generate other values ?

Any advice would be appreciated.
 
I hate cookies, so I'm not here to suggest any good recipes. I just wanted to discount some of the misinformation being posted about.... cookies.

TonyGroves said:
According to the book in front of me, -expires=>'+1m' means to expire after 1 month. It doesn't show any way to make it expire in increments of less than an hour.

Lower case m is for minutes, upper case M is for months. At least when it comes to setting cookies. Annoyingly, this is the inverse of the POSIX standard for formatting dates, but he has that specified correctly.

mbrooks said:
Quite possible the time on your computer is not correct forcing the cookie to automatically expire as it is set.

I believe this is untrue. The only point of setting a relative expiration time is that it is ... relative. It is saved on your system with respect to whatever your current system time is. If you then go and change your time after setting the cookie, then yes, you can avoid/screw up the expiration. But there is no such thing has having the "wrong time" on your computer when setting an relative expiration time cookie.

Kirsle said:
This stands out to me.

Kirsle has good instincts. But instead of changing attribute, I'd just drop it.

Ok, that's enough cookies for me for today. Now I've got that bad aftertaste in my mouth. Gunna take some serious mouthwash to get rid of it I think [sad]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top