devarishi has asked for the wisdom of the Perl Monks concerning the following question:
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!
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Cookie and Session
by aaron_baugher (Curate) on Nov 03, 2011 at 18:05 UTC | |
Re: Cookie and Session
by chromatic (Archbishop) on Nov 03, 2011 at 17:28 UTC | |
by devarishi (Initiate) on Nov 03, 2011 at 17:50 UTC | |
by chromatic (Archbishop) on Nov 03, 2011 at 18:35 UTC | |
by devarishi (Initiate) on Nov 03, 2011 at 18:44 UTC | |
by aaron_baugher (Curate) on Nov 03, 2011 at 22:48 UTC | |
by Anonymous Monk on Nov 04, 2011 at 02:31 UTC | |
|