Something like this might work for you:

my $pass = cookie('cookie'); # if there was a cookie named 'pass' if ( defined $pass) { # if the password in the cookie matches the admin password if ($pass eq $adminpass) { # do administrative stuff } } # there's no cookie, so check for a 'pass' parameter else { $pass = param( 'pass' ); if ($pass eq $adminpass) { # set admin cookie # make sure the name is 'pass' so you can retrieve it # redirect to the current script } }

You might also look in the examples shipped with CGI.pm. cookies.cgi and customize.cgi are pretty good.

Again, simply declaring a hash named %cookie does absolutely nothing to retrieve a cookie. This seems to be the source of your confusion. You could call your hash %not_a_cookie or %magic_php_variable and it would do nothing, since Perl does not care what you name your variables. It does not automatically fill in values for you. You have to retrieve a cookie by name and check its value against the value you have.

Earlier versions of PHP did automagically create variables named after CGI variables, but it's been deprecated and not recommended for quite a while. I'm not aware that any Perl module ever did that -- it opens up a lot of security risks and can cause scary action at a distance.


In reply to Re: Re: Re: Re: Re: Cookie not getting stores by chromatic
in thread Cookie not getting stores by Anonymous Monk

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.