Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks,

I am trying to delete (replace) a cookie sent from a perl-based program on my domain. The problem is I cannot seem to set new cookie exactly like the program set cookie. Since my cookie and the program cookie don't match I cannot overwrite it.

PROGRAM SET COOKIE
Name: TheCookie
Content: anything
Host: foobar.com
Path: /
Send For: Any type of connection
Expires: At end of session


When I try to set the new cookie I get this

MY COOKIE
Name: TheCookie
Content: anything
Host: www.foobar.com
Path: /
Send For: Any type of connection
Expires: At end of session

-- Note the 'Host: www.foobar.com' line


To remove the 'www' I add -domain=>'foobar.com', but then I get 'Domain: .foobar.com' -- 'Domain' not 'Host' and the dot before '.foobar.com'

How do I remove the dot before 'foobar.com' and list the URL as 'Host' not 'Domain'?
  • Comment on Removing dot before cookie host/domain URL

Replies are listed 'Best First'.
Re: Removing dot before cookie host/domain URL
by ikegami (Patriarch) on Jun 24, 2011 at 17:49 UTC

    Why can't you look at how the "perl-based program on my domain" does it?

    Update: Assuming you're using CGI, your claims appear to be incorrect

    $ perl -MCGI=cookie -E' say cookie( -name => "TheCookie", -value => "anything", -domain => "foobar.com", ); ' TheCookie=anything; domain=foobar.com; path=/
      The program seems to use CGI for the cookies (according to the installation module list). However it contains 25 folders, countless files, and a nightmare of global scalars. I haven't yet found the code for the cookie. I thought that it would be easier and more efficient to just overwrite the cookie.

      Below is my code which adds the dot before the URL.
      #!/usr/bin/perl use CGI; $query = new CGI; $cookie1 = $query->cookie( -domain=>'foobar.com', -name=>'TheCookie', -value=>'anything ', -expires=>'+24h', -path=>'/', -secure=> 0); print $query->header(-cookie=>$cookie1); print"<html> <body> Done. </body> </html>"; print $query->end_html;

        Again, I think you are mistaken.

        $ cat > a.pl #!/usr/bin/perl use CGI; $query = new CGI; $cookie1 = $query->cookie( -domain=>'foobar.com', -name=>'TheCookie', -value=>'anything ', -expires=>'+24h', -path=>'/', -secure=> 0); print $query->header(-cookie=>$cookie1); print"<html> <body> Done. </body> </html>"; print $query->end_html; $ perl a.pl Set-Cookie: TheCookie=anything%20; domain=foobar.com; path=/; expires= +Sat, 25-Jun-2011 20:46:56 GMT Date: Fri, 24 Jun 2011 20:46:56 GMT Content-Type: text/html; charset=ISO-8859-1 <html> <body> Done. </body> </html> </body> </html> $

        Upgrade your CGI?

Re: Removing dot before cookie host/domain URL
by choroba (Cardinal) on Jun 24, 2011 at 17:41 UTC
    How does the "perl-based" program send the cookie? Does it use a module? If yes, what is its name?
Re: Removing dot before cookie host/domain URL
by Wolfman (Initiate) on Jun 26, 2011 at 05:24 UTC
    You are on the right track. Let's give the page a name MyTestCookie.cgi
    Delete the -domain=>'foobar.com', so your code looks like this:
    #!/usr/bin/perl use CGI; $query = new CGI; $cookie1 = $query->cookie( -name=>'TheCookie', -value=>'anything ', -expires=>'+24h', -path=>'/', -secure=> 0); print $query->header(-cookie=>$cookie1); print"<html> <body> Done. </body> </html>"; print $query->end_html
    Then load the page (and cookie) without the 'www' in the URL:
    http://foobar.com/MyTestCookie.cgi

    That should do it!