First, I'd like to know what your opinion is on directory security afforded by .htaccess and the web server versus creating a uname & password access with MySQL & PHP.
Second, if you did use the .htaccess method, I have to believe the web server creates a variable with the user's name and that I should be able to get the value of that variable for use in scripts.
Third if you did use MySQL and PHP, how did you protect pages other than the login page - with session vars, call the validation script again or ???
The last time I did this, I dropped a cookie once the user had been validated, and every protected page checked for this cookie and denied access if it wasn't present or valid.
> .htaccess method, I have to believe the web server creates a variable
Unfortunately, I don't think it does. The only solution I've come across (using apache) is to plug your own script into the authentication process and determine the user from there - this page [modperl.com] may give you some ideas
If you are fortunate enough to have access to Apache, there are some authentication modules that are flexible as well, especially those authenticate against external scripts. If you wish to have .htaccess style of security (and convenience) but have flexible auth agent, then these are the ways to go. I use mod_auth_any [itlab.musc.edu] myself, and I found it quite easy to use and write external plugin with.
With HTTP authentication (.htaccess method), on PHP you can use server variables $HTTP_SERVER_VARS['REMOTE_USER'] to find out the username of the authenticated user. I think it is the same with CGI scripts, but they will be stored as environment variables.
Oh! and about tracking... I include a PHP script that when a page loades, it saves user data (from the session variables set at login) and the url loaded.
You could save other data like IP, browser, etc. it depends on what is your goal.
Later on, you can make a script that analizes the database to determine where and what a user went and did.