Sorry to bother again, but this program is just too damned hard to debug! I'm writing a login script for the administrative part of the DSGO. But cgi::carp is telling me when I extract my cookie, I can't get any fields. I figure, this is probably because the cookie isnt set, but %cookies is defined, so how do i confirm this so i dont get an error? I think it may be something even worse than that, because if i comment out the part where it makes $users and $pass the cookie fields it gives me an internal error screen, not even a cgi::carp error.

the code is below

#!/usr/bin/perl #1 load my modules use CGI::Carp qw(fatalsToBrowser set_message); use CGI::Cookie; use CGI qw/:standard/; #2 will write variable loader later $domain = "betterwebber.com"; #3 set up error handler BEGIN { sub handle_errors { my $msg = shift; print "<h1>ERROR</h1><br>"; print "message: $msg"; } set_message(\&handle_errors); } #4 fetch cookies %cookies = fetch CGI::Cookie; $user = $cookies{'user'}->value; $pass = $cookies{'pass'}->value; #5 send user to the login page if not logged in $loggedin = &checklogin($user, $pass); &loginpage if $loggedin = 0; #THE MENU if ($loggedin = 1) { print "you are logged in"; } #6 checklogin - sub checking user and pass sub checklogin { my $userdef = $_[0]; my $passdef = $_[1]; open (FILE, "users.dat"); $usergood = 0; foreach $userdata (<FILE>) { ($usertmp, $passtmp, $accessleveltmp, $emailtmp) = split(/''/, $ +userdata); if ((lc($usertmp) eq lc($userdef)) && (crypt($passdef, $passtmp) + eq $passtmp)) { $usergood = 1; } } close (FILE); return ($usergood); } #7 loginpage - sub that logs in user sub loginpage { my $userdef = ""; my $passdef = ""; if (param()) { $userdef = $query->param('user'); $passdef = $query->param('pass'); } if (&checklogin($userdef, $passdef) == 0) { #desplay login html print header, start_html('Login Page'), hr; h1('You are not logged in. Please do.'), start_form, "Username: ", textfield('user'),p, "Password: ", textfield('pass'),p, submit, end_form, hr; print %cookies; } else { #set cookie and display redirect page $user = new CGI::Cookie(-name => 'user', -value => $userdef, -domain => 'betterwebber.com', -secure => 1 ); $pass = new CGI::Cookie(-name => 'pass', -value => $passdef, -domain => 'betterwebber.com', -secure => 1 ); $selfurl = $query->self_url; print header(-cookie=>[$user,$pass]); print start_html('Loggin in...'), h1('Logging in (hang tight)...'), hr; print "<script language='javascript'>top.location.href = '$selfu +rl'</script>" } }

In reply to Debugging hell!! by toonski

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.