: This article mainly introduces php digest certification. if you are interested in PHP tutorials, refer to it. According ,
A1 = MD5 ( : : )
A2 = MD5 ( : )
Final result: MD5 (MD5 (A1 ): : : : MD5 (A2 ))
Note that the MD5 (A1) and MD5 (A2) values in the preceding line are incorrect. the browser implements MD5 (A1: : : : A2)
$ Realm = 'saberyjs ';
$ Password = '000000'; // This method is only convenient for testing;
If (! Isset ($ _ SERVER ['php _ AUTH_DIGEST '])
{
$ N> header ("www-authenticate: Digest realm = '". $ realm. "', nonce = '". $ nonce. "', algorithm = 'md5', qop = 'auth '");
Header ("HTTP/1.0 401 Unauthorization Required ");
Exit ();
}
Else
{
// Echo 'sset ';
// Echo $ _ SERVER ['php _ AUTH_DIGEST '];
$ Result = parse_auth_digest ($ _ SERVER ['php _ AUTH_DIGEST ']);
// Var_dump ($ result );
// Echo hexdec ($ result ['NC ']);
// Exit ();
If (int) $ result ['NC ']> 1)
{
// Echo 'random number expired ';
$ N> header ("www-authenticate: Digest realm = '". $ realm. "', nonce = '". $ nonce. "', algorithm = 'md5', qop = 'auth '");
Header ("HTTP/1.0 401 Unauthorization Required ");
Exit ();
}
$ A1 = md5 ($ result ['username']. ":". $ result ['realm']. ":". $ password );
// $ A1 = md5 ($ result ['username']. ':'. $ result ['realm']. ':'. $ password ). ':'. $ result ['nonce ']. ':'. $ result ['cnonce '];
$ A2 = md5 ($ _ SERVER ['request _ method']. ":". $ result ['uris ']);
$ Degest = md5 ($ A1 .":". $ result ['nonce ']. ':'. $ result ['NC ']. ':'. $ result ['cnonce ']. ':'. $ result ['qop ']. ':'. $ A2 );
// Var_dump ($ degest );
If ($ degest! = $ Result ['response'])
{
Echo 'verification failed ';
Var_dump ($ result );
}
Else
{
Echo 'successfully ';
}
}
Function parse_auth_digest ($ auth_digest)
{
$ Pairs = array ();
Preg_match_all ('/(\ w +) = [\' "]? ([\/A-z0-9A-Z.] +) [\ '"]? /I ', $ auth_digest, $ result, PREG_SET_ORDER );
Foreach ($ result as $ value)
$ Pairs [$ value [1] = $ value [2];
// Var_dump ($ pairs );
Return $ pairs;
}
?>
The above describes the php digest certification, including the content, hope to be helpful to friends who are interested in the PHP Tutorial.