mod_perl question
Carolyn Hicks
carolyn at bannoy.net
Mon Feb 9 19:27:13 CST 2004
On Tue, Feb 10, 2004 at 12:10:52PM +1100, Scott Penrose wrote:
> On 10/02/2004, at 11:46 AM, Carolyn Hicks wrote:
> >my $url = 'http://'.$r->hostname.$r->uri;
>
> There are three problems with the above approach.
>
> 1) It misses if you are using https - this has bitten me, years after
> implementing code, people turn on HTTPS in the config and my scripts
> break.
>
> 2) It is missing the port number - there is nothing stopping the user
> either providing a redirect on a port or the administrator of the box
> changing the port.
that's true - the above will work for a simple 'default' configuration
but not more complex, non-standard or HTTPS-capable ones.
You can check $ENV{'SERVER_PORT'} to find out if the request came in on
port 80, 443 (hence - probably - HTTPS) or a non-standard one.
> 3) It does not necessarily come in with the host name that was selected
> (ie: the HTTP 1.1)
I think $r->hostname does actually reflect the hostname specified in the
HTTP/1.1 Host header. If you wanted the server's idea of its own
hostname you'd use $r->server->server_hostname.
> Note that the way Apache passes this information in has changed
> dramatically from 1.x to 2.x.
also true, sorry, should have specified that. This is mod_perl 1.x code,
it's probably much simpler in 2.x :)
-carolyn
--
Four fifths of all our troubles in this life would disappear if we would
just sit down and keep still. - C. Coolidge
More information about the Melbourne-pm
mailing list