Here is the first page that is called when the "Submit" button is clicked and "User ID and Password" is passed (via the POST method):

use CGI qw/:standard/; use CGI::Cookie; print "<html><head>\n\r<title>Validating</title></head><body>"; if ($ENV{'REQUEST_METHOD'} eq "POST") { read(STDIN, $request,$ENV{'CONTENT_LENGTH'}) or die "Could not get + query\n"; } @parameters = split(/&/,$request); foreach $p (@parameters){ $p =~ s/\+/ /g; ($para,$value) = split(/=/,$p); $para =~ s/%([0-9A-F][0-9A-F])/pack("c",hex($1))/ge; $value =~ s/%([0-9A-F][0-9A-F])/pack("c",hex($1))/ge; $PAIRS{$para} = $value; } if($PAIRS{"login_id"} eq("admin") && $PAIRS{"login_password"} eq("go") +){ $login_cookie = new CGI::Cookie(-name=>'loginID',-value=>'a +dmin'); $password_cookie = new CGI::Cookie(-name=>'loginPassword',-valu +e=>'go'); header(-cookie=>[$login_cookie,$password_cookie]); print "<script type='text/javascript'> <!-- window.location = 'work_with_cookies.pl'; //--> </script>"; } else{ print "<script type='text/javascript'> <!-- window.location = 'admin_login.html'; //--> </script>"; } print "</body></html>";

And here is the Perl program that is called after creating the cookies:

work_with_cookies.pl

use CGI qw/:standard/; use CGI::Cookie; print ("<html><head>\n\r</head><body>"); %cookies = CGI::Cookie->fetch; print $cookies{"loginID"}; print $cookies{"loginPassword"}; print "<hr />"; print ("</body></html>");

But I am getting nothing on the above page except the Horizontal Line. On the previous page if I use "print" before the "header" then I get the credentials as well as the other stuffs mixed with them as posted in the original post above.

I repeat my question/problem: I am not able to set cookies and fetch/use them from/on the some other page that requires to validate the credentials before displaying its contents.


In reply to Re^2: Cookie and Session by devarishi
in thread 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.