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

Hi all,

How do you use cgi to redirect to other websites?

I want my cgi script to send people to http://www.foo.com once the script has completed.

Help much appreciated.

James

Replies are listed 'Best First'.
Re: Using Perl To Redirect To Other Pages
by thatguy (Parson) on Dec 03, 2002 at 19:33 UTC
    quick and dirty:
    my $url="http://www.foo.com"; my $t=1; # time until redirect activates print "<META HTTP-EQUIV=refresh CONTENT=\"$t;URL=$url\">\n";

    or

    use CGI; my $query=new CGI; print $query->redirect('http://www.foo.com');

    Updated: changed the time until redirect so as not to break the back button per LTjake's suggestion.
    -phill
      Minor point, but this "tip" says not to use META refresh for redirection.

      Perhaps
      print "Location: http://www.foo.com/\n\n";
      is a better "quick-n-dirty"?

      Update: Whoops. Fixed code - missed newlines - hat tip: Cody Pendant.

      --
      Rock is dead. Long live paper and scissors!
        print "Location: http://www.foo.com/";

        Doesn't that need a couple of newlines after it to work?
        --

        ($_='jjjuuusssttt annootthheer pppeeerrrlll haaaccckkeer')=~y/a-z//s;print;
        I agree, Cody. Why do people submit solutions that require others to load the submitters HUGE (favorite) Library of overcoded functions when there is such simple solutions?
        The beauty of the simple. Thanks!