note 81049 added to features.http-auth
| From: | LarsStecken at osu1 dot php dot net | Date: | Tue, 12 Feb 2008 18:23:34 +0000 |
| Subject: | note 81049 added to features.http-auth | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-136071@lists.php.net to get a copy of this message | ||
To anybody who tried the digest example above and didn't get it to work.
For me the problem seemed to be the deprecated use of '\' (backslash) in the regex instead
of the '$' (Dollar) to indicate a backreference. Also the results have to be trimmed off
the remaining double and single quotes.
Here's the working example:
// 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] ? trim($m[3],"\",'") :
trim($m[4],"\",'");
unset($needed_parts[$m[1]]);
}
return $needed_parts ? false : $data;
}
Probably there's a more sophisticated way to trim the quotes within the regex, but I
couldn't be bothered :-)
Greets, Lars
----
Server IP: 69.147.83.197
Probable Submitter: 91.64.193.146
----
Manual Page -- http://www.php.net/manual/en/features.http-auth.php
Edit -- https://master.php.net/note/edit/81049
Del: integrated -- https://master.php.net/note/delete/81049/integrated
Del: useless -- https://master.php.net/note/delete/81049/useless
Del: bad code -- https://master.php.net/note/delete/81049/bad+code
Del: spam -- https://master.php.net/note/delete/81049/spam
Del: non-english -- https://master.php.net/note/delete/81049/non-english
Del: in docs -- https://master.php.net/note/delete/81049/in+docs
Del: other reasons-- https://master.php.net/note/delete/81049
Reject -- https://master.php.net/note/reject/81049
Search -- https://master.php.net/manage/user-notes.php