What actually happens is this: Browser requests cgi script http://www.domain.com/cgi-bin/a.cgi Browser receives "Location: http://www.domain.com/cgi-bin/b.cgi?foo=bar\n\n" Browser requests cgi script http://www.domain.com/cgi-bin/b.cgi?foo=bar Browser displays results of b.cgi In essence, printing a Location header is exactly like the user typing the address specified into the location bar in his browser. I noticed that you did not include http:// in the addresses you gave. If you do not include "http://" in the location, you will get unpredictable results, including most likely a 404 File Not Found error. Note that if you print a Location header, you should print a short message explaining that your browser does not support "Location" headers and provide a link to the site: #!perl # Simple script to auto redirect to a site $site = "http://www.domain.com/cgi-bin/b.cgi?foo=bar"; print "HTTP 302 Move\n"; print "Location: site\n"; print "Content-type: text/html\n\n"; print "Your browser does not support redirects. Please click on the following link to continue: "; print "<A HREF=\"$site\">$site</A>"; __END__ --Quentin ----- Original Message ----- From: "Riccardo Perotti" <perotti@pobox.com> To: "Bruce Van Allen" <bva@cruzio.com> Cc: <macperl-webcgi@macperl.org> Sent: Monday, June 26, 2000 3:28 AM Subject: Re: [MacPerl-WebCGI] Can a cgi script call an URL? > Bruce: > > Thanks a lot! > > Do I understand correctly, then, in assuming that I can make a script do: > > print "Location: www.domain.com/cgi-bin/next.cgi? this=that&foo=fee\n\n" > > and, unless I had done the 'print "Content-type: text/html\n\n"' thing, > it'll just call the other script and pass it that info? > > Would that info get to the other script as $ENV{'QUERY_STRING'} as well? > > What if I passed it a path info ie: "this/path/to/thisfile.txt\n\n" , where > would it be? Is there a $ENV{ ? } for this? > > > Thank you again! > > Riccardo > -- > mailto:perotti@pobox.com > > > > From: Bruce Van Allen <bva@cruzio.com> > > Reply-To: Bruce Van Allen <bva@cruzio.com> > > Date: Sun, 25 Jun 2000 22:48:18 -0700 > > To: Riccardo Perotti <perotti@pobox.com>, "macperl-webcgi@macperl.org List" > > <macperl-webcgi@macperl.org> > > Subject: Re: [MacPerl-WebCGI] Can a cgi script call an URL? > > > > At 10:57 PM 6/25/00, Riccardo Perotti wrote: > >> Hi all: > >> > >> I saw it in some script: > >> > >> Print "Location: www.domain.com/hatever.html" > >> > >> Is this script telling the browser to "go there"? or is it just "printing" > >> the URL into the browser's Location (the user needing to press enter of 'go' > >> or whatever in his bowser)? > > > > "Go there." And, yes to your previous question. If a CGI script named > > www.domain.com/path/a.cgi executes the statement > > > > print "Location: www.domain.com/another/path/b.cgi\n\n"; > > > > then what goes to the user's browser will be the output of b.cgi > > > > assuming b.cgi exists, etc. The first can pass query strings and path > > info to the second, too: > > > > print "Location: www.domain.com/another/path/b.cgi?id=xyz123\n\n"; > > > > print "Location: www.domain.com/another/path/b.cgi/morepath/datafile.txt\n\n"; > > > > But: > > a. the Perl function 'print' is all lower case. > > > > b. "Location: [URL]" is an http header, so it must have a blank line > > immediately following, hence the two 'newlines' (\n\n but see *). > > > > c. If your script has already executed > > > > print "Content-type: text/html\n\n" > > > > in preparation for sending some HTML back to the user, then print > > "Location: ... " won't work, or rather, you'll get "Location: ..." > > printed out somewhere on screen, and it won't be a link either. > > > > > > * Here's a potentially confusing diversion NOT relevant to your > > question about print "Location: ...", but since I used "\n\n" above, > > there's bound to be an objection: > > > > Be careful: in Perl \n stands for whatever the local 'newline' is for > > the OS it's operating under, which means that in MAC OS it's really > > \r or \015 (Carriage Return), in UNIXish it's really \n or \012 (Line > > Feed), and in DOS/Win it's really \n\r or \015\012 (CRLF). Most of > > the time, Perl hides this problem from you, and it's safe to use > > "\n\n". Crossing platforms takes a little more care, such as when > > counting characters, or processing <TEXTAREA> input in which the user > > has hit Return. If you really want to cover all eventualities, then > > filter your input like this: > > > > $line =~ s/\015\012?|\012/\n/g; > > > > HTH > > > > 1; > > > > > > -- > > > > - Bruce > > > > __Bruce_Van_Allen___bva@cruzio.com__Santa_Cruz_CA__ > > > > ==== Want to unsubscribe from this list? > > ==== Send mail with body "unsubscribe" to macperl-webcgi-request@macperl.org > > > ==== Want to unsubscribe from this list? > ==== Send mail with body "unsubscribe" to macperl-webcgi-request@macperl.org > ==== Want to unsubscribe from this list? ==== Send mail with body "unsubscribe" to macperl-webcgi-request@macperl.org