in reply to Serving an html page

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");

Replies are listed 'Best First'.
Re: Re: Serving an html page
by lfindle (Acolyte) on Dec 01, 2001 at 03:06 UTC
    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/)