DekGenius.com
[ Team LiB ] Previous Section Next Section

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

    [ Team LiB ] Previous Section Next Section