problem Redirecting from one cgi page to another...

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • spyka
    New Member
    • Sep 2010
    • 10

    problem Redirecting from one cgi page to another...

    wenevr after the password validation, if its
    correct then instead of redirecting to another
    page its showing ths msg...
    Status: 302 Found Location: http://localhost/cgi-
    bin/Main.cgi

    please gv me the solution for this...

    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";
        my $dbh = DBI->connect
        ("dbi:SQLite:DEVICE.db", "", "",  {RaiseError => 1,
         AutoCommit => 1}) or &dienice("Can't connect to 
         database:$DBI::errstr");
         if ($q->param("Login")){
           my $Password=param('Password');
           if (!$Password){
                 print "Please Enter the Password";
               }
          else{
            my $dbh = DBI->connect 
          ("dbi:SQLite:DEVICE.db", "", "",{RaiseError => 1, 
             AutoCommit => 1});
           my $sth = $dbh->prepare("select * from Settings
               where Password = ?");
          $sth->execute($Password);
          if (my $pass = $sth->fetchrow_hashref)
            {
             print redirect(-url=>'http://localhost/cgi-
              bin/Main.cgi');
    
    
             }
             else{
             print "Invalid Password";
    
               }
            $dbh->disconnect;
                }
                 }
    
            print <<END1;
             <HTML>
             <HEAD>
              <TITLE> </TITLE>
              </HEAD>
    
             <body>
             <form NAME="login"  METHOD="POST">
             <input type="hidden" name="submit"
               value="Submit">
             <TABLE align="center" bgcolor=#B0C4DE>
            <TR>
            <TD> Enter The Password And Click Login</TD>
           </TR> <TR></TR> <TR></TR>  <TR></TR> <TR></TR>
           <TR></TR>
    
              <TR>
             <TD><b>PASSWORD</b> :<input type="password"
          name="Password" size="20" maxlength="15" /></TD>
          </TR> <TR></TR>   <TR></TR> <TR></TR> <TR></TR>
          <TR></TR>
          <TR>
    
           <TR>
             <TD align="center" colspan="2">
             <input type="submit" name="Login" value="Login">
    
            <input type="reset" name="submit" value="Cancel">
           </TD>
           </TR>
    
    
            </TABLE>
    
    
    
              </FORM>
               </BODY>
                </HTML>
               END1
    Last edited by Frinavale; Sep 7 '10, 05:45 PM. Reason: Please post code in [code] ... [/code] tags. Added code tags.
  • chaarmann
    Recognized Expert Contributor
    • Nov 2007
    • 785

    #2
    Please use code tags around your code. (#-button in your webpage-editor).
    The only important part of your code is following line
    Code:
    print redirect(-url=>'http://localhost/cgi-bin/Main.cgi');
    , This is executed in case the password is correct. You could have skipped listing the rest of the code in favor of getting a faster and better answer.

    Anyway, executing this line seems to return status code 302, which says that the redirection site Main.cgi is found. So there is no error, everything runs fine. But maybe you don't want to print the status only, but redirect to it, right?
    So you can do it this way:
    Code:
    use HTTP::Request::Common qw(POST); 
    use LWP::UserAgent; 
    $ua = LWP::UserAgent->new; 
    
    my $req = POST 'http://localhost/cgi-bin/Main.cgi'; 
    
    print $ua->request($req)->as_string;

    Comment

    • chaarmann
      Recognized Expert Contributor
      • Nov 2007
      • 785

      #3
      Wait, it seems there is another way (I never tried so far)
      I found it while googling, so try it out:
      Code:
      #!/usr/bin/perl
      $location = "http://localhost/cgi-bin/Main.cgi";
      print "Status: 302 Found\n";
      print "Location: $location\n";
      print "URI: <$location>\n";
      print "Content-type: text/html\r\n\r\n";

      Comment

      • spyka
        New Member
        • Sep 2010
        • 10

        #4
        THAANKS A LOt..i placed the fst code bt after putting valid password-it dint get redirected to Main.cgi..inste ad it gave ths msg..
        "HTTP/1.1 200 OK Connection: close Date: Tue, 07 Sep 2010 07:21:54 GMT Server: Apache/2.2.16 (Win32) Content-Type: text/html Client-Date: Tue, 07 Sep 2010 07:21:54 GMT Client-Peer: 127.9.2.1:80 Client-Response-Num: 1 Client-Transfer-Encoding: chunked "..nd below tha it gave "Logged in Successfully " which is a statement in Main.cgi...and below gave the Login form of Login.cgi...and url was
        http://localhost/cgi-bin/Login.cgi NOT http://localhost/cgi-bin/Main.cgi...
        .i placed the second code bt as soon i type the filename.cgi in url then it automatically redirects without displaying the form and validating the password...NO IDEA What to place where nw to make this code run as i want it to run...PLEASE HELP ME..

        Comment

        • spyka
          New Member
          • Sep 2010
          • 10

          #5
          i tried the fst code ...it works partially...aft er i put the valid password it dispalys ths message
          HTTP/1.1 200 OK Connection: close Date: Tue, 07 Sep 2010 07:21:54 GMT Server: Apache/2.2.16 (Win32) Content-Type: text/html Client-Date: Tue, 07 Sep 2010 07:21:54 GMT Client-Peer: 127.2.7.1:88 Client-Response-Num: 1 Client-Transfer-Encoding: chunked ...and below tha it gives the MESSAGE "logged in successfully" which is in Main.cgi and below tha again displays the same form of Login.cgi...
          wen i checked out the url then it was
          http://localhost/cgi-bin/Login.cgi NOT

          Comment

          • chaarmann
            Recognized Expert Contributor
            • Nov 2007
            • 785

            #6
            Sorry, I don't understand anything of your "telegram" message. Can you please rephrase in clear, short sentences? And especially pointing out the problem? Or is everything solved now?

            Just relax and analyse the problem calm and slow. After that start writing, not before. Nothing will be solved in a hurry.

            Comment

            Working...