title: How can I redirect the client from one CGI page to another using Perl?
body: <p>My problem is the following. After the password is recognized as valid I need to redirect to <code>main.cgi</code> but I am getting the message as:</p>
  
  <pre><code>Status: 302 Found
  Location: http://localhost/cgi-bin/Main.cgi
  </code></pre>
  
  <p>I know the reason for this is that I am writing this statement after <code>Content-Type</code> so it is taking this as HTML and printing it on screen. I am a newbie to Perl. Can anybody please help me find the solution for this and make my code work the way I want it to? Or please suggest me some alternative code for this, or any link which might help me out.</p>
  
  <pre><code>#!C:\perl\bin\perl.exe
  use strict;
  use CGI qw(:standard);
  use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
  use DBI;
  my $q = new CGI;
  
  print "Content-Type: text/html\n\n";
  
  if ($q-&gt;param("Login")) {
      my $Password = param('Password');
      if (!$Password) {
          print "Please Enter the Password";
      } else {
          my $dbh = DBI-&gt;connect(
              "dbi:SQLite:DEVICE.db",
              "", "",
              {
                  RaiseError =&gt; 1,
                  AutoCommit =&gt; 1
              }
          );
          my $sth = $dbh-&gt;prepare("select * from Settings where Password = ?");
          $sth-&gt;execute($Password);
          if (my $pass = $sth-&gt;fetchrow_hashref) {
              print redirect(-url =&gt; 'http://localhost/cgi-bin/Main.cgi');
          } else {
              print "Invalid Password";
          }
          $dbh-&gt;disconnect;
      }
  }
  
  print &lt;&lt;END1;
  &lt;HTML&gt;
      &lt;HEAD&gt;
          &lt;TITLE&gt; &lt;/TITLE&gt;
      &lt;/HEAD&gt;
      &lt;body&gt;
          &lt;form NAME="login"  METHOD="POST"&gt;
              &lt;input type="hidden" name="submit" value="Submit"&gt;
              &lt;TABLE align="center" bgcolor=#B0C4DE&gt;
                  &lt;TR&gt;
                      &lt;TD&gt; Enter The Password And Click Login&lt;/TD&gt;
                  &lt;/TR&gt;
                  &lt;TR&gt;&lt;/TR&gt;
                  &lt;TR&gt;&lt;/TR&gt;
                  &lt;TR&gt;&lt;/TR&gt;
                  &lt;TR&gt;&lt;/TR&gt;
                  &lt;TR&gt;&lt;/TR&gt;
                  &lt;TR&gt;
                      &lt;TD&gt;&lt;b&gt;PASSWORD&lt;/b&gt; :&lt;input type="password" name="Password" size="20" maxlength="15" /&gt;&lt;/TD&gt;
                  &lt;/TR&gt;
                  &lt;TR&gt;&lt;/TR&gt;
                  &lt;TR&gt;&lt;/TR&gt;
                  &lt;TR&gt;&lt;/TR&gt;
                  &lt;TR&gt;&lt;/TR&gt;
                  &lt;TR&gt;&lt;/TR&gt;
                  &lt;TR&gt;
                  &lt;TR&gt;
                      &lt;TD align="center" colspan="2"&gt;
                          &lt;input type="submit" name="Login" value="Login"&gt;
                          &lt;input type="reset" name="submit" value="Cancel"&gt;
                      &lt;/TD&gt;
                  &lt;/TR&gt;
              &lt;/TABLE&gt;
          &lt;/FORM&gt;
     &lt;/BODY&gt;
  &lt;/HTML&gt;
  END1
  </code></pre>