Hi Monks, I am very new to CGI scripting and I am using ActivePerl 5.8.8 and running Apache 2.2.8 on a Windows XP machine. I am trying to figure out how to move the user to a new page on successful login (checking against a Sybase database which is working fine). I am using the print redirect() function and it simply prints the location on the same page (loginpage.cgi), instead of actually moving to the new page (librarian.cgi). This is my code (The relevant line is print $q->redirect("http://localhost/cgi-bin/librarian.cgi");):
#!/usr/bin/perl -w use CGI qw(:standard); use CGI::Carp qw/fatalsToBrowser warningsToBrowser/; #fatalsToBrowser(1); use DBI; use strict; use Data::Dump qw(dump); my $q = CGI->new(); print $q->header(-cache_control=>"no-cache, no-store, must-revalidate" +); print <<BodyHTML; <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http:/ +/ www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd "> <html lang="en" xml:lang="en" xmlns=" http://www.w3.org/1999/xhtml"> <head> <title>Login Page</title> </head> <body> <form name = "login" action = "loginpage.cgi " method = "GET"> <table> <tr> <td> User Name<br />(25 characters or less) </td> <td> Password<br />(8 - 15 alphanumeric characters) </td> </tr> <tr> <td><input type = "text" name = "UserName" id = "UserName" size = "25" maxlength = "25" tabindex = "0" /> </td> <td><input type = "text" name = "Password" id = "Password" size = "15" maxlength = "15" tabindex = "1" /> </tr> <tr> <td> <input type = "submit" value = "Login" tabindex = "2" /> </td> </tr> <tr> </tr> </table> </form> BodyHTML my ($DBserver, $DBdatabase, $DBuser, $DBpassword) = ('LOCALHOST','test +db','kbuttler','gghy'); my $dbh = DBI->connect("DBI:Sybase:server=$DBserver;database=$DBdataba +se",$DBuser,$DBpassword) or die "Can't connect to Sybase database: $DBI::errstr\n"; my $usernamequery = param("UserName"); my $username_q = $dbh->quote($usernamequery); my $passwordquery = (param("Password")); my $password_q = $dbh->quote($passwordquery); my $sth1 = $dbh->prepare("select username from logintable where userna +me = $username_q "); $sth1->execute(); my $row1 = $sth1->fetchrow_arrayref(); if ( $row1->[0] eq $usernamequery ) { my $sth2 = $dbh->prepare("select password from logintable where pa +ssword = $password_q "); $sth2->execute(); my $row2 = $sth2->fetchrow_arrayref(); $sth2->finish(); if ( $row2->[0] eq $passwordquery ) { print $q->redirect("http://localhost/cgi-bin/librarian.c +gi"); } else { &dienice(qq(The password is invalid.)); exit; } } else { &dienice(qq(Username does not exist.)); exit; } $sth1->finish(); $dbh->disconnect; print end_html; sub dienice { my ($msg) = @_; print "<h1>$msg</h1>"; exit; }
Thanks in advance for any help. -Ken

In reply to how to move to new page on successful login by arnieboy

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.