Jump to content

[SOLVED] Undocumented function: http_digest_parse()


Richard Bowser

Recommended Posts

Reading the PHP manual, I believe it is possible to use digest mode authentication in a PHP script.  This is just a belief because – although Example 34.2 illustrates it – nowhere, in the PHP manual, or at php.net is the function http_digest_parse() documented.  If this is wrong PLEASE tell me!

 

Here’s my situation:  I copied the example verbatim and tried to run it, with the example’s user names & passwords (both pairs).  Twice I had failures.  The dialog box did appear in each case of login attempt, but each time the call to http_digest_parse($_SERVER['PHP_AUTH_DIGEST']) returned a binary 1 (for Failure).  This was no shock to me, since this was only my first try.  I went to look up the function and found: nothing.  Whatsoever.  A brick wall dead-end.

 

I don't want to act like"clueless Lewis", but I guess here I really am!

 

Richard B  ;D

Link to comment
Share on other sites

The function http_digest_parse is NOT a built-in function, it was just a function the PHP.net example-writer wrote to clean up their example code.

 

Here it is:

// function to parse the http auth header
function http_digest_parse($txt)
{
   // protect against missing data
   $needed_parts = array('nonce'=>1, 'nc'=>1, 'cnonce'=>1, 'qop'=>1, 'username'=>1, 'uri'=>1, 'response'=>1);
   $data = array();

   preg_match_all('@(\w+)=(?[\'"])([^\2]+)\2|([^\s,]+))@', $txt, $matches, PREG_SET_ORDER);

   foreach ($matches as $m) {
       $data[$m[1]] = $m[3] ? $m[3] : $m[4];
       unset($needed_parts[$m[1]]);
   }

   return $needed_parts ? false : $data;
}

 

If the function returned 1 then it is probably successful.

 

http://us3.php.net/features.http-auth

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.