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

I know this is a trival question, but I am stuck on this.

In my code I have it when someone logs in, this is printed in the header:
print "Content-type: text/html\n"; print "Set-Cookie: $COOKIE_KEY=$cookie; PATH=$path\n";

My question is this dumb one: "How can I set that same code but using CGI.pm?" For instance in this:
$cookie = cookie (-name => $COOKIE_KEY, -value => $cookie, -expires => "+1d" ); print header(-cookie => $cookie, -P3P=>"policyref=/w3c/p3p.xml" );
Is that the correct way to do it? Because if I change it to that, then when I change the page, I am not logged in any longer, as if that is not "Set-Cookie: $COOKIE_KEY=$cookie; PATH=$path\n"

Thank you!!!
Richard

Replies are listed 'Best First'.
Re: Setting cookie code...
by knoebi (Friar) on Jul 08, 2004 at 15:14 UTC
    this is how i would do it:

    use CGI; use CGI::Session; $cgi = new CGI; $session = new CGI::Session("driver:File", undef, {Directory=>"/tmp"}) +; $cookie = $cgi->cookie(CGISESSID => $session->id); print $cgi->header( -cookie=>$cookie );
    ciao
    knoebi
Re: Setting cookie code...
by powerhouse (Friar) on Jul 08, 2004 at 11:32 UTC
    I worked my way around it. I left it the way I had it, and just after it printed it the old way, not using CGI.pm, I am just redirecting the window back to the URL, then it shows the main menu.... That way it still creates the cookie with the session key, or whatever it needed to do (Not my program).

    I know it did not answer my question, but it works...

    Here is what I did:
    print "Content-type: text/html\n"; print "Set-Cookie: $COOKIE_KEY=$cookie; PATH=$path\n"; print "Location: https://www.frhweb.com/manage.cgi\n\n"; exit;
    thx,
    Richard
Re: Setting cookie code...
by Joost (Canon) on Jul 08, 2004 at 13:05 UTC