Octavian Rasnita wrote:
Hi all,

I want to redirect the browser to a certain page using:

print "Location: http://$ENV{SERVER_NAME}$ENV{HTTP_REFERER}";;


In this case you will need to add two new lines as well, to conclude the header, assuming this is the last line of the header.


or

$q->redirect("http://$ENV{SERVER_NAME}$ENV{HTTP_REFERER});


Better choice....

Well, I would like to use the second way even though it might have a small
overhead, but I would like to be able to have the "http://"; part (the
scheme) in a certain variable, so the make the program functional even if I
run it under https.

I have searched to see if there is an environment variable that holds the
"http://"; part, but I saw that there is no such a thing.


I am not sure HTTP_REFERER is what you want above, it will be the full address of the page you came from, including the 'http://' as well as the domain, etc. So tacking it onto the end of a new server name seems a little odd, though there would be times when I could see you using it. Perhaps SCRIPT_URI or QUERY_STRING is what you are after.


Please advice me how to make a redirection workable without changing the
script when I will use it under SSL.


Depending on what you are after you should be able to check the environment variables to see if you are in a secure session, such as the SERVER_PROTOCOL, or at the very least check the port to see if it is 443. Alternatively you could pull the first part of SCRIPT_URI if you are on Apache, essentially everything up to the first colon.


print "Content-type: text/html\n\n";
print "<pre>\n";

foreach my $key (sort(keys(%ENV))) {
    print "$key - $ENV{$key}\n";
}
print "</pre>\n";

Will print your environment out...

Thank you.

Teddy


HTH,

http://danconia.org

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to