Reputation: 845
I am sending data from A.cgi
to B.cgi
. B.cgi
updates the data in the database and is supposed to redirect back to A.cgi
, at which point A.cgi
should display the updated data. I added the following code to B.cgi
to do the redirect, immediately after the database update:
$url = "http://Travel/cgi-bin/A.cgi/";
print "Location: $url\n\n";
exit();
After successfully updating the database, the page simply prints
Location: http://Travel/cgi-bin/A.cgi/
and stays on B.cgi
, without ever getting redirected to A.cgi
. How can I make the redirect work?
Upvotes: 0
Views: 1113
Reputation: 24083
Use CGI's redirect method:
my $url = "http://Travel/cgi-bin/A.cgi";
my $q = CGI->new;
print $q->redirect($url);
Upvotes: 1
Reputation: 2382
Location:
is a header and headers must come before all ordinary output, that's probably your problem. But doing this manually is unneccessarly complicated anyways, you would be better of using the redirect function of CGI.pm
Upvotes: 2