Saturday, May 24, 2008

Perl Python CGI script page redirection

Share at Facebook

After processing your Perl/CGI script you may need to redirect it to a specific link. To do this, most of the cases the choice is below code.

print "Location:\n\n";

But I found that this is not work most of the cases, May be I'm missing something. If anyone know this, can guide me.

But I used to write the below line instead of above one. This one work with me since this is the HTML code printing into browser using Perl.
print '<meta http-equiv="refresh" content="0;url=">';

There is another way to redirect. Which is printing the JavaScript code into browser. I'm giving one example to do this.
<script type="text/javascript">location.href='';</script>

By the way, Above will work for Python/CGI too. Appreciate to post other ways if you guys know.

More Perl article is here

1 comment:

Matt said...

This works for me in Python, perhaps not the best way, but it seems to work.

print "Status: 302 Moved"
print "Location:"