vsailas has asked for the wisdom of the Perl Monks concerning the following question:

Hi,

I was looking for ways to get Remote Hostname like $ENV{"USER_NAME"} on apache server.
Is there a way to get the the name of the host machine, preferably perl or else any other way.
I cannot use .htaccess as our authentication is database based.
Any help or direction greatly appreciated.

Thanking all in advance!
Sailas

Replies are listed 'Best First'.
Re: Remote HostName using CGI
by ikegami (Patriarch) on Feb 15, 2008 at 07:12 UTC

    Returns either the remote host name or IP address. if the former is unavailable:

    $cgi->remote_host()

    By the way, there's also

    $cgi->remote_user()

    as an alternative to $ENV{USER_NAME}. In both case, $cgi is a CGI object.

Re: Remote HostName using CGI
by pc88mxer (Vicar) on Feb 15, 2008 at 07:05 UTC
    Information about the client's host is passed to CGI scripts in $ENV{REMOTE_HOST} (the client's host name) and/or $ENV{REMOTE_ADDR} (the client's ip address.) If the server doesn't set $ENV{REMOTE_HOST} it should set $ENV{REMOTE_ADDR}.

    Does this answer your question?

    In general it is not possible to get the "user name" (i.e. the identity used to log into the client's host) of the client. The concept of a user's identity is something that your application has to create.