Note: for this tutorial, we'll assume that Register Globals is set to Off, as it is by default in current PHP versions.
If your web site is on an Apache web server, you can capture the user name from the login and then convert it to a session variable. When an .htaccess login is successful, the user name goes into an array named $_SERVER. ($HTTP_SERVER_VARS prior to PHP 4.1). The value is $_SERVER['PHP_AUTH_USER']. Note: the caps do matter. These arrays and element names are case sensitive.
Using the Auth User Variable "as is"
If all of the pages your authorized user will be accessing are in the directory or directories protected by the .htaccess file, you can simply use the $_SERVER['PHP_AUTH_USER'] variable. It's available until the user navigates away from the protected area.
Converting to a Session Variable.
To use the login user name with pages outside the protected area, you need to convert it to a session variable.
|