in reply to Get Remote Username

There are several approaches.

One is to dump the database contents regularly into a .htusers files and let Apache do all the dirty work.

Another possibility is to send the 401 Autentication Required HTTP header yourself, and deal with the response by yourself.

Or you can set up your own authentication handler.