How can I access the apache basic-auth username in a PHP script?
HTTP Auth in the PHP Manual would be a good starting place.