This article mainly introduces the enhanced mhash function implemented by PHP. when the default mhash function is used, an error is reported and two solutions are found, for more information, see the error message "Fatal error: Call to undefined function mhash ()" when using the php encryption function mhash today ()
Mhash is a built-in function of php, but an error is reported when it is used ..
The following two methods are summarized:
1. import the php_mhash.dll extension file. In addition, you need to import libmhash. dll (the load dependency file of the mhash Library ),
Load LoadFile C:/php/libmhash. dll in the Apache configuration file Httpd. conf ".
2. use the custom mhash enhancement function.
The code is as follows:
Function hmac_md5 ($ key, $ data)
{
If (extension_loaded ('mhash '))
{
Return bin2hex (mhash (MHASH_MD5, $ data, $ key ));
}
$ B = 64;
If (strlen ($ key)> $ B)
{
$ Key = pack ('H * ', md5 ($ key ));
}
$ Key = str_pad ($ key, $ B, chr (0x00 ));
$ Ipad = str_pad ('', $ B, chr (0x36 ));
$ Opad = str_pad ('', $ B, chr (0x5c ));
$ K_ipad = $ key ^ $ ipad;
$ K_opad = $ key ^ $ opad;
Return md5 ($ k_opad. pack ('H * ', md5 ($ k_ipad. $ data )));
}
The $ key and $ data parameters in the hmac_md5 function correspond to the original 3 and 2 parameters of mhash.
Both methods can smoothly use the mhash encryption function of php.