I am trying to get this script to redirect me to a url upon validation of l/p. It validates just fine. then instead of redirecting at the right time the script continues to run. here is the code, and the output to the browser is below it.
#!/usr/bin/perl use strict; use warnings; use CGI qw ( :standard ); use Fcntl qw ( :flock ); use XML::Parser; if (param) { my ($parser, $document, $users); local($::flag); $::flag=0; open(USERS, "../../xml_final/users/users.xml") || die "Could not open users.xml $!"; flock(USERS, LOCK_SH); print header, start_html(-title => "Login" ,-style => { -src => "../../xml_final/db.css"}), title ("please login"); print start_html; $parser= new XML::Parser(); $parser->setHandlers( Start => \&start_handler, Char => \&char_handler ); $document = $parser->parse (\*USERS); close (USERS); sub start_handler{ my ($expat, $element, %attributes) =@_; if ($::flag==0 && $element eq "username") { $::flag=1; } if ($::flag==1 && $element eq "password") { $::flag=2; } } sub char_handler { my ($expat, $text) =@_; if ($::flag==1 && $text eq (param("username"))) { $::flag=1; } if ($::flag==2 && $text eq (param("password"))) { print h1("LOGIN IN IS ALL GOOD"); print redirect("viewdb.pl?username=(param(username)"); print end_html; } elsif ($::flag==2 && $text ne (param("password"))) { print h1 ("incorrect password"); $::flag=0; print p({-align=>'CENTER'},a{-href=>"login.pl"},"Try Agian?" +); print end_html; #print a link back to login.pl } } } else { print header, start_html(-title => "Login" ,-style => { -src => "../../xml_final/db.css"}), title ("please login"); print start_form; print h1({-align=>'CENTER'}, "Please login"); print p({-align=>'CENTER'},"username:", textfield( -NAME=>"username" )); print p({-align=>'CENTER'},"password:", password_field( -NAME=>"password" )); print p({-align=>'CENTER'},submit("send"),reset); print end_form; print p({-align=>'CENTER'},a{-href=>"newuser.pl"},"New User?"); print end_html; }
and the browser output is Content-Type: text/html; charset=ISO-8859-1 <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML Basic 1.0//EN" "http://www.w3.org/TR/xhtml-basic/xhtml-basic10.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="en-US"><head><title>Login</title> <link rel="stylesheet" type="text/css" href="../../xml_final/db.css" /> </head><body><title>please login</title><?xml version="1.0" encoding="utf-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML Basic 1.0//EN" "http://www.w3.org/TR/xhtml-basic/xhtml-basic10.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="en-US"><head><title>Untitled Document</title> </head><body>

LOGIN IN IS ALL GOOD

Status: 302 Moved location: viewdb.pl?username=(param(username) </body></html>

incorrect password

Try Agian?

</body></html>

In reply to A CGI redirect problem by krujos

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.