jason dancks
jason dancks

Reputation: 1142

perl: firefox rejects my cookie?

I have the following script at �://192.168.1.3/homeworks/hw10/testcookie.cgi:

#!/usr/bin/perl -wT
use CGI qw(:standard);
use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
use CGI::Cookie qw(cookie);

use strict;
use warnings;


sub makecookie {
        return my $cookie = cookie(-name=>'hw10',
                        -value=>shift,
                        -expires=>shift,
                        -path=>'/hw10/testcookie.cgi',
                        -domain=>'192.168.1.3',
                        -secure=>1);
}

my $cgi = CGI->new();
my $cookie = makecookie("192.168.1.3",'+3d');
print STDOUT $cgi->header(-cookie=>$cookie);
print STDOUT $cgi->start_html("Test Cookie");
print STDOUT "<h1>TEST</h1>";
print STDOUT $cgi->end_html();

I checked with Live headers that something was sent:

GET /homeworks/hw10/testcookie.cgi HTTP/1.1
Host: 192.168.1.3
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:34.0) Gecko/20100101 Firefox/34.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Connection: keep-alive

HTTP/1.1 200 OK
Date: Wed, 24 Dec 2014 16:11:24 GMT
Server: Apache/2.2.22 (Debian)
Set-Cookie: hw10=192.168.1.3; domain=192.168.1.3; path=/hw10/testcookie.cgi; expires=Sat, 27-Dec-2014 16:11:24 GMT; secure
Vary: Accept-Encoding
Content-Encoding: gzip
Content-Length: 258
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: text/html; charset=ISO-8859-1
----------------------------------------------------------

but firefox says there is no cookie associated with the site. Why does firefox reject the cookie?

Upvotes: 1

Views: 73

Answers (1)

ikegami
ikegami

Reputation: 386501

The path component of the URL is

/homeworks/hw10/testcookie.cgi

yet you're trying to set a cookie for

/hw10/testcookie.cgi

The latter is not contained by the former, so that's an error. You might want to use

-path => $cgi->url( -absolute => 1 )

instead of

-path => '/hw10/testcookie.cgi'

This may not be the only error. You didn't provide the URL you requested, so I don't know if you're using HTTP or HTTPS. You'll have problems if you're using HTTP because you specified the cookie should only be provided over secure connections.

Upvotes: 1

Related Questions