1

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 1

1

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];
Sign up to request clarification or add additional context in comments.

1 Comment

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.