Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

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

by dkubb (Deacon)
on Jun 28, 2001 at 20:29 UTC ( #92357=note: print w/replies, xml ) Need Help??

in reply to to $Env{'HTTP_HOST'} or to $Env{'SERVER_NAME'}, that is the question.

IMHO, the best way to get at that information is through's method virtual_host():

use CGI; my $cgi = CGI->new; my $domain = $cgi->virtual_host;

It will attempt to Do The Right Thing in determing the virtual host's name. I believe it is cleaner, and more portable to use CGI's methods to access the CGI specific environment variables, than to access them directly by hand.

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

Replies are listed 'Best First'.
Re: (dkubb) Re: (2) to $Env{'HTTP_HOST'} or to $Env{'SERVER_NAME'}, that is the question.
by RatArsed (Monk) on Jun 29, 2001 at 13:05 UTC
    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"}


      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. $ENV{'SERVER_NAME'} returns "localhost" $ENV{'HTTP_HOST'} returns "localhost:8001"

      The actual values of course depends on you environment setting.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://92357]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (3)
As of 2022-12-06 00:42 GMT
Find Nodes?
    Voting Booth?

    No recent polls found