Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi!! I want to redirect my perl program to an html page under a particular condition. Please help me. I am working with Active Perl on IIS

Replies are listed 'Best First'.
Re: Serving an html page
by btrott (Parson) on Jun 08, 2000 at 21:34 UTC
    Would using a Location header do what you want? If not, I'm not sure what you mean.
    print "Location: http://www.foo.com/bar.html\n\n";
    Or, if you're using CGI.pm (which you should be):
    my $q = new CGI; print $q->redirect("http://www.foo.com/bar.html");
      I am also trying to redirect a user to an HTML page if a certain condition is met. I am using cgi.pm and when I try the code you mentioned (included below) it gives me the error: Status: 302 Found Uri: Location: Content-type: text/html
      my $q = new CGI; print $q->redirect("http://busybody.w1.com/html/2010assignment.html");
      Any ideas on what I am doing wrong?
      Thanks-
      Laura
      My entire script is as follows:
      #!/usr/local/bin/perl -w # 2010b.pl use CGI; require ("cgi-lib.pl"); my $q = CGI->new(); print $q->header(); $studentid = $q->param('studentid'); $password = $q->param('password'); $CSC = $q->param('CSC'); $assignment = $q->param('assignment'); $file = $q->param('path'); if ($CSC eq "CSC2010") { $openfile = "CSC2010.txt"; open (IN, "<$openfile") or die "Can't open $openfile\n"; $foundusername = false; $foundpassword = false; while ($line = <IN>) { chomp($line); my ($realstudentid,$realpassword) = split /\|/, $line; if ($realstudentid eq $studentid){ $foundusername = true; if ($realpassword eq $password){ $foundpassword = true; print $q->redirect("http://busybody.w1.com/html/2010assignmen +t.html\n\n"); exit; } } } if ($foundusername eq false ) { print "username not found!<br>"; } if ($foundpassword eq false) { print "bad password!<br>"; } }
        You should not print HTTP response header with $q->header() if you are going to do redirect with $q->redirect. Status: 302 Found Uri: Location: Content-type: text/html is not an error - it is correct HTTP header your script should issue to do redirect. You see it only because your script already issued HTTP header with $q->header(). (Well almost correct HTTP header - after Location: there should be URL where script redirects)

        BTW you don't need require ("cgi-lib.pl"); if you are using CGI.pm.

        --
        Ilya Martynov (http://martynov.org/)

Re: Serving an html page
by Anonymous Monk on Jun 09, 2000 at 20:07 UTC
    Thanx, the first method worked