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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.