CGI Cookie Path Question

CGI Cookie Path Question

am 26.12.2005 16:53:07 von DFS

Hello All,

All my cookies are created with the path set to "/" and everything was
working fine. The one and only way I set my cookies was the line below.
And I know I have it only once as I keep it in one of my function modules
and call it with a function call.

$q->redirect(-cookie=>$cookies,-uri=>$new_url);

Everything was peechy keen until I started using fullpaths for the $new_url
value (i.e. http://myserver/cgi-bin/loggedon.pl"). The cookie path stayed
the same, "/", but now I was no longer reading them. Once I went back to
calling my function with $new_url no longer having the path, just
"loggedon.pl", everything went back to normal.

I know changing the path within cookie affect who can and can't read them.
But as well, all my cookies are created through the same function call, and
the path is hardcoded to "/".

So it seems to me, that the path from COOKIE is being ignored, and being
replaced with the path from the URI.

Is anyone familiar with anything like this?

Thanks ahead,

Daniel

Re: CGI Cookie Path Question

am 26.12.2005 19:00:32 von Gunnar Hjalmarsson

Daniel Kaplan wrote:
> All my cookies are created with the path set to "/" and everything was
> working fine. The one and only way I set my cookies was the line below.
> And I know I have it only once as I keep it in one of my function modules
> and call it with a function call.
>
> $q->redirect(-cookie=>$cookies,-uri=>$new_url);
>
> Everything was peechy keen until I started using fullpaths for the $new_url
> value (i.e. http://myserver/cgi-bin/loggedon.pl").

Are you hardcoding the domain as well? Maybe using something else but
'myserver', e.g. 'www.myserver'?

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

Re: CGI Cookie Path Question

am 27.12.2005 00:33:08 von DFS

"Gunnar Hjalmarsson" wrote in message
news:41aphrF1dofmrU1@individual.net...

> Are you hardcoding the domain as well? Maybe using something else but
> 'myserver', e.g. 'www.myserver'?

yes.... as long as I just say "NextScript.pl" and not
http://myswerver.com/cgi-bin/NextScript.pl everything is cool.

Very weird

Re: CGI Cookie Path Question

am 27.12.2005 00:39:50 von Gunnar Hjalmarsson

Daniel Kaplan wrote:
> Gunnar Hjalmarsson wrote:
>>Are you hardcoding the domain as well? Maybe using something else but
>>'myserver', e.g. 'www.myserver'?
>
> yes....

In that case, try

http://www.myserver.com/cgi-bin/NextScript.pl

> as long as I just say "NextScript.pl" and not
> http://myswerver.com/cgi-bin/NextScript.pl everything is cool.
>
> Very weird

Learn more about cookies at http://www.cookiecentral.com/

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

Re: CGI Cookie Path Question

am 27.12.2005 00:54:12 von DFS

"Gunnar Hjalmarsson" wrote in message
news:41bde1F1dg76vU1@individual.net...

> In that case, try
>
> http://www.myserver.com/cgi-bin/NextScript.pl
>

I'll check it out, though I went and changed it all instances to relative
paths as opposed to absolute.

But am curious as to the cause, since from the documentation (as I read it)
does not mention that the path of the URI in calling redirect affects the
path of the cookie.

Re: CGI Cookie Path Question

am 27.12.2005 01:14:54 von Gunnar Hjalmarsson

Daniel Kaplan wrote:
> Gunnar Hjalmarsson wrote:
>>In that case, try
>>
>> http://www.myserver.com/cgi-bin/NextScript.pl
>
> I'll check it out, though I went and changed it all instances to relative
> paths as opposed to absolute.
>
> But am curious as to the cause, since from the documentation (as I read it)
> does not mention that the path of the URI in calling redirect affects the
> path of the cookie.

Let's say you set a cookie via this script:

#!/usr/bin/perl
# setcookie.pl
print "Set-cookie: test=xyz; path=/\n";
print "Content-type: text/plain\n\n";
print "Cookie set for $ENV{HTTP_HOST}\n";
__END__

by invoking it as http://www.myserver.com/cgi-bin/setcookie.pl

Then, if you try to 'read' the cookie via:

#!/usr/bin/perl
# readcookie.pl
print "Content-type: text/plain\n\n";
print "Available cookies: $ENV{HTTP_COOKIE}\n";
__END__

you must invoke the latter as http://www.myserver.com/cgi-bin/readcookie.pl

The browser will _not_ include the cookie in the cookie header if you
invoke readcookie.pl as http://myserver.com/cgi-bin/readcookie.pl

HTH

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

Re: CGI Cookie Path Question

am 27.12.2005 01:26:43 von Gunnar Hjalmarsson

Daniel Kaplan wrote:
> the documentation (as I read it) does not mention that the path of
> the URI in calling redirect affects the path of the cookie.

If the path is set explicitly, it doesn't. OTOH, the _host_ of the URI
does affect the cookie domain.

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl