Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Nov 2011
    Thanked 0 Times in 0 Posts

    Lightbulb 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:

      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

    Last edited by FishMonger; 11-27-2011 at 05:08 PM. Reason: Code tags added. Please use them when posting code.

  2. #2
    Super Moderator
    Join Date
    May 2005
    Southern tip of Silicon Valley
    Thanked 233 Times in 226 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.
    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->h1("Testing Cookies"),
          $Cgi->pre(Dumper \%cookies),


Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts