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

I've run into this problem many times before under numerous conditions. While print $query->header; how can you redirect the user to another page without the use of any external language such as java? I tried print "Location: $user\n"; but rather than directing the user it literally prints that on the browser.

Any suggestions?

Thanks so much!

VFT

Replies are listed 'Best First'.
Re: Redirecting Problem
by DamnDirtyApe (Curate) on Aug 08, 2002 at 16:53 UTC

    Straight from the CGI docs:

    print $query->redirect('http://somewhere.else/in/movie/land');

    _______________
    DamnDirtyApe
    Those who know that they are profound strive for clarity. Those who
    would like to seem profound to the crowd strive for obscurity.
                --Friedrich Nietzsche
      Just as an FYI, I had the same issue as VFT when I was learning CGI. The print $query->redirect('http://somewhere') ; must not appear AFTER a print $query->header() ; as it IS your header.

      "Nothing is sure but death and taxes" I say combine the two and its death to all taxes!
        Thanks, I'm so glad I am not the only one that's been through this! And thanks for letting me know it IS my header, which still sorta confuses me...does that mean I will no longer need print $query->header; , I just replace it with the redirect script you have?

        I installed it by deleting my other header print, but I ran into another problem. I am doing:
        my $url; $url = 'www.site.com';
        But when I try $query->redirect('$url') ; it's trying to show me you can't use a scalar here. Is this true?

        Thanks so much!

          A reply falls below the community's threshold of quality. You may see it by logging in.
        A reply falls below the community's threshold of quality. You may see it by logging in.
Re: Redirecting Problem
by hacker (Priest) on Aug 08, 2002 at 16:51 UTC
    print "Location: http://www.somewhere.else/\n\n";
    No headers, nothing else required. Just print that.
Re: Redirecting Problem
by DigitalKitty (Parson) on Aug 08, 2002 at 23:52 UTC
    Hi VFT,

    Single quotes don't allow variable interpolation where as double quotes do. Here is an example:
    #!c:\perl\perl.exe -wT use strict; use CGI; use CGI::Carp qw( fatalsToBrowser ); my $q = new CGI; my $url = "http://www.perl.org"; print $q->redirect("$url"); print $q->header();

    Hope this helps,
    -Katie