note 90324 added to features.http-auth
| From: | jon at toolz4schoolz dot com | Date: | Thu, 16 Apr 2009 13:10:31 +0000 |
| Subject: | note 90324 added to features.http-auth | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-153388@lists.php.net to get a copy of this message | ||
I can't get the second example to work. The regular expression is beyond the scope of this
programmer so I rewrote it as seven easy-to-read regular expressions and it works.
Here's the whole function http_digest_parse() that works for me:
<?php
// 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]]);
}
*/
$res = preg_match("/username=\"([^\"]+)\"/i", $txt, $match);
$data['username'] = $match[1];
$res = preg_match('/nonce=\"([^\"]+)\"/i', $txt, $match);
$data['nonce'] = $match[1];
$res = preg_match('/nc=([0-9]+)/i', $txt, $match);
$data['nc'] = $match[1];
$res = preg_match('/cnonce=\"([^\"]+)\"/i', $txt, $match);
$data['cnonce'] = $match[1];
$res = preg_match('/qop=([^,]+)/i', $txt, $match);
$data['qop'] = $match[1];
$res = preg_match('/uri=\"([^\"]+)\"/i', $txt, $match);
$data['uri'] = $match[1];
$res = preg_match('/response=\"([^\"]+)\"/i', $txt, $match);
$data['response'] = $match[1];
//return $needed_parts ? false : $data;
return $data;
}
?>
----
Server IP: 69.147.83.197
Probable Submitter: 81.233.224.95
----
Manual Page -- http://www.php.net/manual/en/features.http-auth.php
Edit -- https://master.php.net/note/edit/90324
Del: integrated -- https://master.php.net/note/delete/90324/integrated
Del: useless -- https://master.php.net/note/delete/90324/useless
Del: bad code -- https://master.php.net/note/delete/90324/bad+code
Del: spam -- https://master.php.net/note/delete/90324/spam
Del: non-english -- https://master.php.net/note/delete/90324/non-english
Del: in docs -- https://master.php.net/note/delete/90324/in+docs
Del: other reasons-- https://master.php.net/note/delete/90324
Reject -- https://master.php.net/note/reject/90324
Search -- https://master.php.net/manage/user-notes.php