Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

Cookies Help

by ACJavascript (Acolyte)
on Dec 10, 2002 at 01:06 UTC ( [id://218706]=perlquestion: print w/replies, xml ) Need Help??

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

Hy perl monks, I need help creating a cookie and reading it.
Heres my code what am i doing wrong?????

$FORM{'username'} == the persons username...
$Data = {'HTTP_COOKIE'}; ($Name,$info) = split(/=/,$Data); if($Name eq $FORM{'username'}){ &WelcomeUser; }else{ $CookieName=$FORM{'username'}; print "Set-Cookie: Name=$CookieName;\n"; &WelcomeAndRedirect; }


Help please :)

Replies are listed 'Best First'.
Re: Cookies Help
by Ovid (Cardinal) on Dec 10, 2002 at 01:27 UTC

    You probably should check out the documentation for cookie handling. I'd also recommend reading through my CGI course (link at bottom).

    use CGI qw(:standard); # reading a cookie my $cookie_value = cookie( $cookie_name ); # creating a cookie my $cookie = cookie( -name => $cookie_name, -value=> $some_value ); # And setting the cookie (while printing the header) print header( -cookie => $cookie );

    The above is a simple example of how to do this. Read the docs for more information about how it works.


    New address of my CGI Course.
    Silence is Evil (feel free to copy and distribute widely - note copyright text)

      Hey thanks alot,,, but dont you need a module to use,, ??? or am i totaly wrong..hehehe
        yeah, but at this point, is pretty much standard. do something like this to create a cookie:

        use CGI;
        $q = new CGI;
        my $cookie1 = $q->cookie(-name => 'test', -value => 'test');
        print $q->header(-cookie => $cookie1); 
        create multiple cookies like so: -cookie => [$cookie1, $cookie2]
Re: Cookies Help
by dingus (Friar) on Dec 10, 2002 at 08:23 UTC
    Re: Receiving Cookie Values contains the hints I gave the last time this kind of question was asked.

    use CGI or die; is also required reading for this topic :)


    Enter any 47-digit prime number to continue.
      Thanks alot!!!!!!!!!!! guys/gals... :)


Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://218706]
Approved by Ovid
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (3)
As of 2024-07-13 07:04 GMT
Find Nodes?
    Voting Booth?

    No recent polls found

    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.