Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

revised: 10/22/2000 - unhappy with original "review"

CGI::Cookie is an easy way of managing cookies for your website.

CGI::Cookie is authored by Lincoln D. Stein

There are many available documents and examples available to show you how to utilize this module. I am hoping that I can create a review, and not just another coding example.

Below is an example, however it is not near as complete as the examples that may be found at the following sites:

I have used this module on the following platforms without issue.

  • Solaris
  • HP-UX
  • Linux (SuSE, Caldera)
  • FreeBSD 3.x
  • Windows (95,98,NT)

Why use it?

  • Session management
  • User login management and security
  • Impress/scare your users by tracking what they do
  • Saving data to be used later when you lack a database
  • Because it's easier than doing it by hand

What I've used it for

  • Secure login session management
  • Manage webpage "themeing"

For those wanting a quickie usage without following the above links...

This example will use CGI and CGI::Cookie. It will create a cookie, set the cookie via the HTTP header and then retrieve the cookie and display it.

In my example, this is what gets sent to the browser to create the cookie...obtained via an NT command line. Note that at a command line, you will not see the set cookie in the print loop, as there was no browser to do the storing/retrieving.

Set-Cookie: CookieName=CookieValue; path=/C:\wardk\cookie.pl
Date: Wed, 13 Sep 2000 21:00:35 GMT
Content-Type: text/html

Here is the code that created the above. Happy coding!

#!/usr/bin/perl use CGI; use CGI::Cookie; $q = new CGI; # Create a new cookie $cookie = new CGI::Cookie(-name=>'CookieName',-value=>'CookieValue'); # set the Cookie print $q->header(-cookie=>$cookie); print $q->start_html; %cookies = fetch CGI::Cookie; # print the cookie while (( $k,$v) = each %cookies) { print "<p>$k = $v"; } print $q->end_html; exit;

In reply to CGI::Cookie by wardk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (3)
As of 2024-04-20 08:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found