Monks,
i'm reeeally confused! I hope someone can help. I know these are all trivial Qs, but i suppose someone must ask them! I have few subs that should handle an admin page, where users can add, delete etc. db entries. my script starts with setting up cookies for user and password. once that is done there is the sub login that checks for valid users and upon errors calls the sub error_page,else it prints a menu using sub la_menu:
sub login { my $username = $q->param('username'); my $password = $q->param('password'); my $SQL = "SELECT username, password FROM user WHERE username = + '$username'"; my @row; @row = $dbh->selectrow_array($SQL); unless (exists $row[0]) { &error_page; exit; } unless ($password eq "$row[1]") { error_page(); } la_menu(); }#end#of#sub#login sub error_page { print $q->start_html(-title=>"some.com| ERROR", -style=>{src=>" +../../mycss.css"}); print<<HTML; <p class="edit_header"><strong>some.com | ERROR</strong></p> <h2 class="error">Invalid username or password</h2> <p class="footer"><a href="http://www.some.com">some.com</a></p> HTML } #end#of#sub#error_page sub la_menu { if ($q->param( "add" )) { add_new(); } elsif ($q->param( "edit" )) { edit(); } print<<HTML; <form method="get" name="la_manu" class="edit"> <input name="edit" type="submit" value="Edit Properties " class="b +uttons"> <input name="add" type="submit" value="Add New" class="buttons"> </form> HTML }#end#of#sub#la_menu
until here it works fine, however once one of the buttons of the menu sub is pressed it always prints the error page. i guess what i am unclear is, if i should check for valid user with every subroutine. i also tried to check if the cookies equal the username and password passed from the login form, the result seems to be the same! this is the sub that gets called when a button in sub la_menu is pressed:
sub add_new { my $user = $q->cookie('username'); my $pass = $q->cookie('password'); if ($cookie eq $user, $cookie1 eq $pass) { print<<HTML; ... HTML }else { error_page(); } }
hope this is clear?! thanks
r_mehmed

Edited 2003-03-05 by mirod: changed the title


In reply to Trouble with cookies being used for validation (was: cookies) by r_mehmed

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.