Donnie has asked for the wisdom of the Perl Monks concerning the following question:
<meta http-equiv="refresh" content="0;url=http://redirect.url.here?any + cgi=options&here=too">;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Calling a cgi with another cgi
by LTjake (Prior) on Oct 16, 2002 at 01:16 UTC | |
But, to do a redirect try this: Other than that, I'd need a better description of your problem. -- Rock is dead. Long live paper and scissors! | [reply] [d/l] |
|
Re: Calling a cgi with another cgi
by jarich (Curate) on Oct 16, 2002 at 08:55 UTC | |
Your meta tag tells the browser to go to the next script. If your initial cgi say, takes a form submission, massages/corrects the data and then redirects to the next page that should be fine. If, instead you want it to take the form submission, massage or correct/validate the data and then call another script if it's good or the previous script if it's bad there might be better options. Of course, you've probably realised now that you haven't given us enough information. Here might be some answers to your question, note that in each I only call one script. It shouldn't be too hard for you to throw conditionals around stuff if that's what you need to do: The blocks around each option are more for visual distinction and are not strictly necessary (except for the fact that I do my $otherscript twice etc. If you go with the first idea I also suggest moving the use LWP::UserAgent; to the top of your script up near use strict; because it'll make more sense to your scripts maintainer. If you have any questions about these answers feel free to ask. If you want to have another go at trying to ask your question that might be a good idea too. ;) You can most easily do this by replying to your original post here with the answers the the questions we've asked you. Hope it helps. jarich | [reply] [d/l] [select] |
|
Re: Calling a cgi with another cgi
by true (Pilgrim) on Oct 16, 2002 at 01:57 UTC | |
Don't output a content-type header in your cgi. The Location tag is a redirect ala http & apache. Just output the Location call above and you will be redirected on the server. jtrue | [reply] [d/l] |
by davis (Vicar) on Oct 16, 2002 at 08:46 UTC | |
Actually, no. Sorry, but that doesn't work. I've just tried the following script:
And it failed - no redirection, just the string "Location:http://www.perlmonks.org/\n\n" in my browser. The reason it failed on my machine is because (IIRC) Apache looked at the first few lines of output of the script, didn't see a header, and so added the header itself (specifying plain text) before sending the output of the script. You can make yours work by adding the line
above the existing print() line. I've also just tried the following: Which outputs: When called on the command line. When called by the webserver, it outputs a valid, correct, and working header that redirects the client. I'm not completely against printing the headers yourself for such a simple task, but I am against printing headers wrongly. Using the CGI module saves you from having to read the RFCs to find out why your script didn't work, and will save time: it took about 5 seconds to produce the CGI.pm method, and closer to 5 minutes for me to make your version work1 When there's a monastery full of monks suggesting 'use CGI;', perhaps they're onto something
Please Note: 1: - I'm not good at creating HTTP headers, so I don't claim that to be a good comparison. davis Is this going out live? No, Homer, very few cartoons are broadcast live - it's a terrible strain on the animator's wrist Update: After an interesting ChatterBox discussion with true, and some playing around with webserver configs, I've come to the following conclusion (for apache): true's solution works, if:
The CGI.pm solution works whatever because it checks to see if modperl's running, and whether the header's been sent. References: the modperl guide, and Writing Apache Modules with Perl and C. | [reply] [d/l] [select] |
by true (Pilgrim) on Oct 16, 2002 at 09:08 UTC | |
I know CGI.pm is cool. This does redirect on my apache 1.3.6 webserver. I tried it again to be sure.
FYI I also tried to add your 302 tag but it failed. The httpd log reports:"...malformed header from script. Bad header=HTTP/1.1 302 Moved:..." cheers, jtrue | [reply] [d/l] [select] |
by true (Pilgrim) on Oct 16, 2002 at 10:44 UTC | |
I should have clarified my current non-modperl status in my earlier post. Sadly i can't test under mod_perl right now. But, if anybodies is curious, I tested the code below successfully on Win2k apache and linux apache. Running perl 5.005 sans mod_perl Also, note on both platforms, adding the line print "HTTP/1.1 302 Moved\n"; causes a mal-formed header error. The Motto of the story... use da CGI module! jtrue <edit:made grammar edit | [reply] [d/l] [select] |
by Donnie (Acolyte) on Oct 16, 2002 at 18:49 UTC | |
by Donnie (Acolyte) on Oct 16, 2002 at 19:41 UTC | |
| [reply] |
by true (Pilgrim) on Oct 17, 2002 at 07:21 UTC | |
Donnie, Don't give up just yet. Make sure you don't print anything to STDOUT before you output the Location redirect. Try this code on your server as is, then add your code, avoid printing to STDOUT.
Things you probably know anyway. | [reply] [d/l] |
|
Re: Calling a cgi with another cgi
by belg4mit (Prior) on Oct 16, 2002 at 02:07 UTC | |
-- | [reply] |
|
Re: Calling a cgi with another cgi
by nutshell (Beadle) on Oct 16, 2002 at 01:29 UTC | |
(include onto your page the contents of 'http://redirect.url.here?anycgi=options&here=too') --nutshell | [reply] [d/l] |
|
Re: Calling a cgi with another cgi
by Donnie (Acolyte) on Oct 16, 2002 at 20:01 UTC | |
| [reply] |
by jarich (Curate) on Oct 17, 2002 at 08:05 UTC | |
For example: will cause an internal server error because we're not printing out the required HTTP header. Our webserver doesn't care what script prints out that header, but it does expect that it'll be printed out before anything else is. If we change file2.cgi to be: we don't get any error. Perhaps that is something you need to check. jarich | [reply] [d/l] [select] |