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

Thanks to all the wise monks who helped me with my last problem. It works a treat now. On to todays question. I'm trying to send a cookie using the CGI mehod. I have managed to do this so far by redirecting e.g.
print $query->redirect(-location=>"wherever",-cookie=>$cookie);
I would like to generate the HTML from the CGI program, which I thought was done like this:
print $query->header(-cookie=>$cookie);
and then proceed with rest of HTML page. This method does not seem to send the cookie to the browser. Any suggestions? Thanks

Replies are listed 'Best First'.
Re: Cookies
by Masem (Monsignor) on May 05, 2001 at 22:59 UTC
    Remember that the header() function must be the first thing you print to the page, and if you are going to send cookies, they have to be sent at this point. So make sure you aren't using header() twice, once blank and once with a cookie set.


    Dr. Michael K. Neylon - mneylon-pm@masemware.com || "You've left the lens cap of your mind on again, Pinky" - The Brain
Re: Cookies
by Chady (Priest) on May 05, 2001 at 22:04 UTC

    close enough:

    $cookie = $query->cookie(-name=>$name, -value=>$value, -expires=>'+1h'); print $query->header(-cookie=>$cookie);
    and your question was??
    He who asks will be a fool for five minutes, but he who doesn't ask will remain a fool for life.

    Chady | http://chady.net/
      I am using exactly that code and when I checked my cookie folder, the cookie wasn't there.
        When working with cookies, you can set your browser to prompt you before setting cookies, this way you can test if any are set and press no if you want to have to delete your cookie.

        Olly

        I am having trouble loggin in so I won't recieve any votes :(