Recipe 6.13 Accessing the Authenticated Username

Problem

You want to know the name of the user who has authenticated.

Solution

Consult the environment variable REMOTE_USER.

In a Server-Side Include (SSI) directive, this may look like:

Hello, user <!--#echo var="REMOTE_USER" -->. Thanks for visiting.

In your CGI code, it might look like:

my $username = $ENV{REMOTE_USER};

Discussion

When a user has authenticated, the environment variable REMOTE_USER is set to the name with which she authenticated. You can access this variable in CGI programs, SSI directives, PHP files, and a variety of other methods. The value will also appear in your access_log file.

Note that, while it is the convention for an authentication module to set this variable, there are reportedly some third-party authentication modules that do not set it, but provide other methods for accessing that information.

See Also

  • Recipe 6.14



Apache Cookbook
Apache Cookbook: Solutions and Examples for Apache Administrators
ISBN: 0596529945
EAN: 2147483647
Year: 2006
Pages: 215

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net