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

Hi. I set a cookie in my perl script:

print STDOUT qq |Set-cookie: $mailaddress=$address\n|;
print STDOUT qq |Content-type: text/html\n\n|;

and in Netscape the cookie is immediately set and usable by other Netscape opened windows. In IExplore, on the contrary, the cookie is not immediately recognized by other IExplorer opened windows.

Did I set the cookie wrong ? Thanks from Alvise.

Replies are listed 'Best First'.
Re: Setting a cookie
by projekt21 (Friar) on May 15, 2002 at 09:15 UTC

    As name is the only required attribute on Set-Cookie I see no problem with your code (except that you have a lowercase "cookie" instead of the correct uppercase "Cookie" in "Set-Cookie"). For more info:

    For Perl CGIs I strongly recommend using CGI. Creating Cookies is easy then (along with other thingies):
    use CGI; $query = CGI->new; $cookie = $query->cookie(-name=>'sessionID', -value=>'xyzzy', -expires=>'+1h', -path=>'/cgi-bin/database', -domain=>'.capricorn.org', -secure=>1); print $query->header(-cookie=>$cookie);

    alex pleiner <alex@zeitform.de>
    zeitform Internet Dienste

Re: Setting a cookie
by Ryszard (Priest) on May 15, 2002 at 09:15 UTC
    I would strongly recommend you use CGI.pm if you're able to.

    Setting a cookie is then as simple as: $q->cookie(<cookie values here>).

Re: Setting a cookie
by wardk (Deacon) on May 15, 2002 at 16:18 UTC
    Without an expire in the future you have a session cookie, i.e. it will expire when the browser closes. Appears that Netscape considers new windows to be part of the session, where IE is not. Are you opening new windows from within the open browser ( file->new ) or are you starting it up from an icon on a desktop? Seems a new window via file->new would be considered part of a session, while new windows from icons would be a separate instance, thus separate session.

    Using CGI.pm to at least generate the cookie would provide you with an easy method of creating a properly formatted expires= string. good luck!