in reply to (dkubb) Re: (2) to $Env{'HTTP_HOST'} or to $Env{'SERVER_NAME'}, that is the question.
in thread to $Env{'HTTP_HOST'} or to $Env{'SERVER_NAME'}, that is the question.

In reality, all that's going to do is give you $ENV{"HTTP_HOST"} (or $ENV{"SERVER_NAME"} in the highly unlikely event of the Host: request header being specified)

The Host header (read $ENV{"HTTP_HOST"}) which is manditory for HTTP/1.1 (and IIRC also for HTTP/1.0) specifies the host name for the request; this was designed specifically for "virtual hosting".

If you already have a CGI object floating about, then I'd recommend using $cgi->virtual_host. If you don't, it's probably easier to just use $ENV{"HTTP_HOST"}

--
RatArsed

  • Comment on Re: (dkubb) Re: (2) to $Env{'HTTP_HOST'} or to $Env{'SERVER_NAME'}, that is the question.
  • Select or Download Code

Replies are listed 'Best First'.
Re^3: (2) to $Env{'HTTP_HOST'} or to $Env{'SERVER_NAME'}, that is the question.
by Anonymous Monk on Oct 13, 2020 at 07:46 UTC

    Perhaps something has changed in all these years: using PERL 5.14 and Apache virtual hosting all of these gives you a different result:

    $CGI->virtual_host() returns DNS name ex. www.my.address.com $ENV{'SERVER_NAME'} returns "localhost" $ENV{'HTTP_HOST'} returns "localhost:8001"

    The actual values of course depends on you environment setting.