For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > February 2005 > redirection









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author redirection
Octavian Rasnita

2005-02-02, 3:56 pm

Hi all,

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

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

or

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

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.

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

Thank you.

Teddy

JupiterHost.Net

2005-02-02, 3:56 pm

Hello,

> 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.


parse it out of CGI::url()
Wiggins d'Anconia

2005-02-02, 3:56 pm

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
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com