Is it possible in PHP to access the login name of a user authenticated with server's native HTTP digest authentication (as starkly opposed to a PHP implementation of the same HTTP authentication protocol)?
1 Answer
The data you are after is provided in the HTTP header sent from the client (as per https://www.rfc-editor.org/rfc/rfc2617 ), namely the header Authorization.
In PHP this header can be retrieved like so:
$header = $_SERVER['HTTP_AUTHORIZATION'];
The header contains a number of key value pairs separated by commas. The username is in the username key, you can extract this by something like:
preg_match('/username="([^"]+)"/', $header, $matches);
$username = $matches[1];
1 Comment
Szczepan Hołyszewski
Thanks, I figured it out in the meantime (accepting still). The confounding factor was that I mistakenly believed the digest auth to have been set up for the document root while it was only set up for a subdir. The component I was working on, residing in another subdir, obviously did not get the Authorization header.