max-age attribute not working, How do you make a cookie expire? |
max-age attribute not working, How do you make a cookie expire? |
jmrathbun |
Jun 29 2011, 09:02 PM
Post
#1
|
Newbie Group: Members Posts: 15 Joined: 8-June 11 Member No.: 14,726 |
I'm trying to set a cookie that will expire in 24 hours. I've tried
CODE Set-Cookie: score=10; path=/; expires=time()+86400 and I've tried CODE Set-Cookie: score=10; path=/; max-age=86400 both on Unix and on Windows servers, but in every case I get a session cookie only. What's wrong? |
jmrathbun |
Jun 30 2011, 11:59 AM
Post
#2
|
Newbie Group: Members Posts: 15 Joined: 8-June 11 Member No.: 14,726 |
Sorry to be so unclear. According to various online sources, this code goes at the top of the html document and it executes as expected (leaving a cookie) except the cookie expires at the end of the browser session instead of 24 hours later as the code indicates it should. Here's the whole script:
CODE #!/usr/local/bin/perl use warnings; use strict; use CGI; my $cgi=new CGI; use diagnostics; print "Set-Cookie: topic=Consciousness; path=/; expires=time()+86400\n"; print "Set-Cookie: score=10; path=/; max-age=86400\n"; print "Set-Cookie: smarts=20; path=/; expires=time()+86400\n"; print "Set-Cookie: playlevel=30; path=/; max-age=86400\n"; print $cgi->header; print $cgi->start_html('Set Cookie'); print $cgi->h1('The cookie has been set!'); print $cgi->end_html; |
Lo-Fi Version | Time is now: 26th April 2024 - 08:59 AM |