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

I'm sorry in advance for asking this question:

Can I use the same cookie in different pages?

I tried to read in a cookie created by one page into another CGI Perl program, and it apparently doesnt work but I cant find any docs on cookies that tell me more info.

For example, index.cgi creates the cookie, all is well, it loads and reloads fine for index.cgi, now I want another perl.cgi program to use this cookie.

Can anyone help me?

I use the classic code to read the cookie in:

%newb = $co->cookie('newb') ;

Thanks!
newb

Replies are listed 'Best First'.
Re: Stupid Cookie Question
by converter (Priest) on Feb 28, 2002 at 22:31 UTC

    The Unofficial Cookie FAQ has some good information on cookie implementation.

    In a nutshell, make sure that the path and domain values aren't overly-restrictive. The domain field is evaluated right to left, so that ".example.com" would cause the client to transmit the cookie with requests to www.example.com, foo.example.com, etc. If the domain were specified as www.example.com, the client would not transmit the cookie with requests sent to foo.example.com.

    As others have suggested, if you specify the path value as '/', the client will transmit the cookie for all requests as long as the domain field permits it.

Re: Stupid Cookie Question
by PriNet (Monk) on Feb 28, 2002 at 21:36 UTC
    yes, you can use the cookie over your entire domain if you use the path=/ in your set cookie-header....

    you mean there's any easier way?
Re: Stupid Cookie Question
by Speedy (Monk) on Feb 28, 2002 at 21:51 UTC
    Try:

    %cookies = fetch CGI::Cookie;

    foreach (keys %cookies) {
       do_something($cookies{$_});
    }