Gossamer Forum
Home : General : Perl Programming :

Netscape cookie woes

Quote Reply
Netscape cookie woes
Hi!

I've been going round 'n round trying to set a cookie in netscape. I can't seem to get it to work. Currently, I'm trying to use the CGI module interface, but still no luck. (see http://www.gossamer-threads.com/...ew=&sb=&vc=1

Here's what Ive got:

In Reply To:
#!/usr/bin/perl

use CGI;
$query = new CGI;

$cookie = $query->cookie(-name=>'cookie',
-value=>'chocolate',
-expires=>'+5d',
-path=>'/',
-domain=>'.mydomain.com');

$location = 'http://mydomain.com';

print $query->redirect( -cookie => $cookie, -location => $location);

exit;
The cookie is set fine in MSIE, but not in Netscape. (The redirect part works in both, though.)

I'm using Netscape version 4.5

Anyone see any reason why this isn't working? (Note, I DO have cookies turned on!)

Thanks for any assistance!



Matt Glaspie
Quote Reply
Re: Netscape cookie woes In reply to
-domain=>'.mydomain.com');

Why the leading dot?

Wil

Quote Reply
Re: Netscape cookie woes In reply to
Um the leading dot is quite acceptible as it allows for the cookie to be used under any sub-domain.

You may wish to read this tutorial on cookies....very helpful:

http://www.perldoc.com/cpan/CGI/Cookie.html

Notice they use leading dots too Wink

Mods:http://wiredon.net/gt/download.shtml
Installations:http://wiredon.net/gt/
Quote Reply
Re: Netscape cookie woes In reply to
Ah, right. Just a hunsh.

Wil

Quote Reply
Re: Netscape cookie woes In reply to
Hi,

Set cookie warnings on in Netscape and double check what is happening. Try using an html redirect and see if that works (just to track down the problem).

Cheers,

Alex

--
Gossamer Threads Inc.
Quote Reply
Re: Netscape cookie woes In reply to
Thanks for the replies so far...

After some further expirimentation, I discovered the problem lies with the
-domain=>'.mydomain.com' line.

Removing this parameter completely allows the cookie to be set in both msie & netscape. (fyi, I did try with/without leading dot.) However, I'm not yet sure what the ramifications of not setting the domain will be... does not seem to make a difference.

Does it make sense that the -domain parameter is not supported by Netscape? Am I overlooking something?

Thanks,

Matt Glaspie
Quote Reply
Re: Netscape cookie woes In reply to
It is supported by Netscape...at least in the cookie codes I am using in my site(s), which is similar to what you had, but I use a cookie hash (%cookie) to store the values and it works fine between both clients (IE and Netscape).

Regards,

Eliot Lee Wink
http://anthrotech.com/
Quote Reply
Re: Netscape cookie woes In reply to
:-))

Wil

Quote Reply
Re: Netscape cookie woes In reply to
I don't doubt you Eliot, but I'm having a hard time figuring out how using a hash would make any difference.

I'm 99% sure the problem is in the actual setting of the header, since I also tried the following with the same results (or rather lack thereof):

In Reply To:
#!/usr/bin/perl

print "Content-type: text/html\n";

$newcookie = 'Set-Cookie: cookieflavor=chocolate; expires=Sat, 18-Oct-2003 12:00:00 GMT; path=/; domain=.mydomain.com';
print STDOUT "$newcookie\n";

print "\n";

print STDOUT <<ENDOFPAGE ;
<html>
<head>
<title>Cookies - set</title>
</head>

<body>
Cookie set.
</body>
</html>

ENDOFPAGE

exit;
Removing the domain= bit allowed the cookie to be set in Netscape.

Would you mind sharing an example of the cookie code you're using?

Thanks,


Matt Glaspie
Quote Reply
Re: Netscape cookie woes In reply to
I use the following which works in MSIE and NS

Code:
$cookie = $IN->cookie( -name => 'CookieName',
-value => $var,
-expires => '+2yr',
-domain => ''
);

print $IN->header( -cookie => $cookie );
Mods:http://wiredon.net/gt/download.shtml
Installations:http://wiredon.net/gt/
Quote Reply
Re: Netscape cookie woes In reply to
I already posted codes that work in this forum awhile ago.

Regards,

Eliot Lee Wink
http://anthrotech.com/
Quote Reply
Re: Netscape cookie woes In reply to
Eliot, I searched using a variety of different keywords (including things like "%cookie", "% cookie" and "cookie eliot"), but could not find the post you mention.

You wouldn't remember by chance the thread's title or any keywords in the thread? (You know, aside from "cookie") Smile

Thanks for assistance,

Matt G