How to redirect from one CGI to another

痞子三分冷 提交于 2019-12-20 06:12:32

问题


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?


回答1:


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




回答2:


Use CGI's redirect method:

my $url = "http://Travel/cgi-bin/A.cgi";
my $q = CGI->new;
print $q->redirect($url);


来源:https://stackoverflow.com/questions/19912499/how-to-redirect-from-one-cgi-to-another

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!