Why doesn't Safari set cookies from my Perl CGI script?

I have a Perl-based website that is trying to set multiple cookies for the first time users visit, and I just noticed that Safari has stopped setting all but the first cookie that is being sent. On the first visit, two cookies must be set, which are the "location" and the "referrer". In IE and Firefox, cookies are set correctly, but Safari only sets the cookie "location". I tried changing names, values, etc., and I came to the conclusion that Safari simply sets the first of two cookies:

Here is the code that sets cookies:

# Add location cookie if necessary if(!$query->cookie('location') && $user_location) { my $cookie = $query->cookie(-name=>'location',-value=>qq|$user_lcoation|,-domain=>".domain.com",-path=>'/',-expires=>'+1Y'); push(@cookies,$cookie); } # Add referrer if first visit if(!$query->cookie('referrer')) { if($ENV{'HTTP_REFERER'}) { my $cookie = $query->cookie(-name=>'referrer',-value=>$ENV{'HTTP_REFERER'},-domain=>".domain.com",-path=>'/',-expires=>'+3M'); push(@cookies,$cookie); } else { my $cookie = $query->cookie(-name=>'referrer',-value=>'unknown',-domain=>".domain.com",-path=>'/',-expires=>'+3M'); push(@cookies,$cookie); } } if(scalar(@cookies)) { print $query->header(-cookie=>\@cookies); } 

Here is what I get when I try to access a website from curl:

 curl -so /dev/null -D - http://domain.com HTTP/1.1 200 OK Date: Thu, 18 Feb 2010 20:19:17 GMT Server: Apache/2.0.63 (Unix) mod_ssl/2.0.63 OpenSSL/0.9.8e-fips-rhel5 mod_auth_passthrough/2.1 mod_bwlimited/1.4 FrontPage/5.0.2.2635 PHP/5.2.8 mod_perl/2.0.4 Perl/v5.8.8 Set-Cookie: location=Dallas; domain=.domain.com; path=/; expires=+1Y Set-Cookie: referrer=unknown; domain=.domain.com; path=/; expires=Wed, 19-May-2010 20:19:20 GMT Transfer-Encoding: chunked Content-Type: text/html; charset=ISO-8859-1 

Any ideas? I do not understand what I can do to help solve this problem, as it seems that my script is passing them correctly. Thank you in advance for any ideas or ideas you may have!

+4
source share
3 answers

Look at the expires date in the first cookie header - it's literal +1Y instead of the actual standard date it should be. I assume your version of Safari is choking on this and simply refuses to parse the remaining cookie headers.

To set the annual expiration date, the correct syntax is -expires => '+1y' (lowercase Y).

+5
source

Try updating CGI.pm (do cpan CGI ). I had a similar problem with cookies that were resolved with the CGI.pm update.

0
source

a bit late for aswer, but later better than never: an easy way, without having to reinstall / update CGI.pm, specify the date when you want your cookie to expire using DateTime.pm:

 my $cookie = CGI->new->cookie( -name=>'cookie_name', -value=>'value', -domain=>$ENV{'HTTP_HOST'}, -expires=>((DateTime->now->set_time_zone('local'))->add(months=>1)->strftime("%a, %d %b %Y %I:%M:%S GMT")), -path=>'/', );
my $cookie = CGI->new->cookie( -name=>'cookie_name', -value=>'value', -domain=>$ENV{'HTTP_HOST'}, -expires=>((DateTime->now->set_time_zone('local'))->add(months=>1)->strftime("%a, %d %b %Y %I:%M:%S GMT")), -path=>'/', ); 

There I have a cookie that will last 1 month. I tested it on safari under XP, it works fine. hope this helps

0
source

Source: https://habr.com/ru/post/1301744/


All Articles