Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Simple question about CGI/Perl and html redirection

by vonman (Acolyte)
on Mar 27, 2001 at 21:08 UTC ( [id://67537]=perlquestion: print w/replies, xml ) Need Help??

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

I am new to both HTML and CGI scripting and have what is most likely a very simple question. I have an html script that redirects it's input for a form to a cgi script with the POST method. Once inside of the cgi script the system decides on what web page the user should be redirected to. The code below sucessfully reads in the form data
use CGI qw(:standard); ReadEntry();
If the variable $filename is the complete http://xyz.html name of where I want to redirect to. What is the line that I need to enter after my ReadEntry()? Thanks.

Replies are listed 'Best First'.
Re: Simple question about CGI/Perl and html redirection
by arturo (Vicar) on Mar 27, 2001 at 21:18 UTC

    I'm not sure exactly what you're asking. To issue a redirect, you can send the Location header, as in

    print "Location:$url\n\n"; #which is wrong, see below.

    Which must be issued BEFORE you send any output to the browser. Alternately, you can use CGI.pm's redirect function:

    print CGI::redirect($url);

    I'd use the CGI param function to get data from forms, though.

    Note: neither of these will 'send along' your POSTed data to the following URL.

    Philosophy can be made out of anything. Or less -- Jerry A. Fodor

      print "Location:$url\n\n";
      By standards, there must be a space after the colon. If you fail to do that, the server or browser must error-correct your code, and that may not always happen consistently.

      -- Randal L. Schwartz, Perl hacker

        Sigh. yep. Not having to remember little things like that is a good argument for using CGI::redirect($url), IMO.

        Philosophy can be made out of anything. Or less -- Jerry A. Fodor

Re: Simple question about CGI/Perl and html redirection
by little (Curate) on Mar 27, 2001 at 21:12 UTC
    search for redirect( ) in the cgi.pm docs.

    Have a nice day
    All decision is left to your taste
Re: Simple question about CGI/Perl and html redirection
by Chady (Priest) on Mar 27, 2001 at 21:19 UTC

    or you can do this:

    print "Location: $filename\n\n";

    just be sure that you haven't printed an HTML header yet.


    Update: arturo was faster, and his post contains more info, please disregard


    He who asks will be a fool for five minutes, but he who doesn't ask will remain a fool for life.

      No, don't. I forgot the space (d'oh) in the Location type solution. =)

      Philosophy can be made out of anything. Or less -- Jerry A. Fodor

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://67537]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (4)
As of 2024-04-19 11:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found