Please Note:

OS: Windows XP
Web Server: IIS
Perl: ActivePerl


I am finding it difficult to deal with cookie in Perl CGI. I have a webpage, say Login Page, where on the admin enters the credentials and after validating the credentials he/she is presented with subsequent webpages as he/she browses them. No webpage must be directly opened by entering its URL / Bookmark without providing the credentials.

Hence, I need to store the credentials and they need to be checked by each web page before their contents are displayed.

By following this perl doc: http://perldoc.perl.org/CGI/Cookie.html I have been able to store cookies and display them somehow but am not sure as to how to make them accessible to the Next Web Page that does not store/create them and just needs to use their values.

I used this:

$login_cookie = new CGI::Cookie(-name=>'loginID',-value=>'admin +'); $password_cookie = new CGI::Cookie(-name=>'loginPassword',-value=>' +go'); print header(-cookie=>[$login_cookie,$password_cookie]);

The last line causes the following output to be displayed:

Set-Cookie: loginID=admin; path=/ Set-Cookie: loginPassword=go; path=/ + Date: Thu, 03 Nov 2011 16:42:20 GMT Content-Type: text/html; charset +=ISO-8859-1

And these lines do not work:

%cookies = CGI::Cookie->fetch; for (keys %cookies) { print($cookies{$_}); }

Most likely, I am not able to understand as to how to handle cookie in Perl CGI. This is where I am finding myself very poor and am being forced to move to some other stuff such as PHP wherein handling Cookie is just like going to a candy shop. However, that is not what I want to. I want to know how to do these stuffs in Perl. And that's why I an here in this Monastery!


In reply to Cookie and Session by devarishi

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.