Only possibe when PHP is loaded as an Apache module, as it allows you to directly control the HTTP headers sent to the client and see tose headers they sent backk. Here is the page on php.net which explains how to do it:

http://uk2.php.net/manual/en/features.http-auth.php