Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
print header; print start_html("Login"); ... print redirect("http//");

You can't use both redirect and output something else to the browser. If I understand what your code is doing, you probably want to wait with outputting the header and HTML until it's clear the user isn't being redirected.

I see a few more points in your code that could be improved:

  • Declare variables for the smallest possible scope where they are needed, for example while( my ($id, $user, .... This will lead to less scoping issues; for example you've declared ($l,$a,$z) twice, which isn't necessary (and you should prefer my over our).
  • Avoid the variable names $a or $b as they are special for sort.
  • You don't need the foreach my $p (param()) loop since you're accessing the parameters directly by name.
  • You don't need the $query = new CGI; since you're not using it anywhere; use either's object-oriented interface or its functional interface.
  • You're doing the if($role eq $z) test twice; the second time it'll always be true.
  • Instead of scanning the database yourself, look into SQL's WHERE clause and make sure to use placeholders, as documented in DBI.
  • If train/main.htm doesn't do any authentication of its own, people will be able to easily circumvent this login form by entering the URL directly.
  • See UP-TO-DATE Comparison of CGI Alternatives - personally I'd strongly recommend Mojolicious instead of; see Mojolicious::Guides::Tutorial, it's a very different and IMHO much nicer way to do web development. Update: I just posted an example.

In reply to Re: 302 Found Location Message by haukex
in thread 302 Found Location Message by Walter_T

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (4)
As of 2022-07-05 12:34 GMT
Find Nodes?
    Voting Booth?

    No recent polls found