note 90324 deleted from features.http-auth by cmb

From: Date: Sun, 06 Oct 2019 08:32:50 +0000
Subject: note 90324 deleted from features.http-auth by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-212533@lists.php.net to get a copy of this message
Note Submitter: jon at toolz4schoolz dot com ---- 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; } ?>

« previous php.notes (#212533) next »