Go Back   CodingForums.com > :: Server side development > Perl/ CGI

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-27-2011, 09:19 AM   PM User | #1
jcuypers
New to the CF scene

 
Join Date: Nov 2011
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
jcuypers is an unknown quantity at this point
Lightbulb Problem setting cookies

Hi,

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:

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();
So here are my test results:

Elinks (text web browser under debian): OK
Internet explorer 8: NOK
Firefox: 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

Regards
J.

Last edited by FishMonger; 11-27-2011 at 04:08 PM.. Reason: Code tags added. Please use them when posting code.
jcuypers is offline   Reply With Quote
Old 11-27-2011, 04:21 PM   PM User | #2
FishMonger
Super Moderator


 
Join Date: May 2005
Location: Southern tip of Silicon Valley
Posts: 2,753
Thanks: 2
Thanked 149 Times in 144 Posts
FishMonger will become famous soon enoughFishMonger will become famous soon enough
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();
FishMonger is offline   Reply With Quote
Reply

Bookmarks

Tags
cgi, cookies, perl

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:25 PM.


Advertisement
Log in to turn off these ads.