Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
Thread: Problem setting cookies
11-27-2011, 09:19 AM #1
- Join Date
- Nov 2011
- Thanked 0 Times in 0 Posts
Problem setting cookies
I'm currently working on a perl script which needs to store cookies to retain user preferences. For some reason, I can't get it to work (not fully at least).
Can you please give me some hints bcs I cant see the problem anymore.
Here's my code:
#!/usr/bin/perl use strict; use warning; use CGI::Carp qw(fatalsToBrowser); use CGI; use CGI::Cookie; my $Cgi = new CGI; my $Cookie = CGI::Cookie->new( -name => 'test', -value => 'abc', -expires => '+2d' ); print $Cgi->header(-cookie => $Cookie); print $Cgi->start_html('test'); print $Cgi->end_html();
Elinks (text web browser under debian): OK
Internet explorer 8: NOK
Sniffing the actual response traffic to IE8/Firefox with wireshark shows the cookie but it is not taken into account. Changed the security settings on both web browser to almost none but still not accepted....
I played around with all kinds of cookie settings but it doesn't work. The only thing I still thought was that I'm currently working with a fake test domain name which is in the localhost file (I use vmware / apache / mod_perl with virtual hosting). So there's "www.websitea.be" in my hosts file (both on server and client). so I tried to change the domain name to something official like yahoo.com but it doesnt work.
I also use NTP to sync date & time so that there can't be any problem with the expiration of the cookies...
I'm almost desperate. wasted some hours on this already
Thx for you help
Last edited by FishMonger; 11-27-2011 at 04:08 PM. Reason: Code tags added. Please use them when posting code.
11-27-2011, 04:21 PM #2
- Join Date
- May 2005
- Southern tip of Silicon Valley
- Thanked 164 Times in 159 Posts
First, please put your code within code tags when posting. Also instead of retyping your code, it's best to copy/paste to prevent typos (e.g., the missing s on use warning;) and unwanted indentation. Due to the issue I just mentioned, that code won't compile and as such would generate an "Internal Server Error".
After correcting those issues, your code works correctly for me in both IE and Firefox.
Try this adjusted version.
Code:use strict; use warnings; use CGI::Carp qw(fatalsToBrowser); use CGI; use CGI::Cookie; use Data::Dumper; my $Cgi = CGI->new; my %cookies = CGI::Cookie->fetch; my $Cookie = CGI::Cookie->new( -name => 'test', -value => 'abc', -expires => '+2d' ); print $Cgi->header(-cookie => $Cookie), $Cgi->start_html('test'), $Cgi->h1("Testing Cookies"), $Cgi->pre(Dumper \%cookies), $Cgi->end_html();