


PHP encryption 3DES error Call to undefined function: mcrypt_module_open() How to solve, mcryptmoduleopen_PHP tutorial
Jul 12, 2016 am 08:54 AMPHP encryption 3DES error Call to undefined function: mcrypt_module_open() How to solve, mcryptmoduleopen
I am also a newbie in PHP. I learned about the basic principles of php through w3cschool and started writing. But still a rookie.
Regardless of whether the 3DES encryption method is correct or not, the methods are all online. When running, an error was reported, which killed the little brother. After much searching, I finally found a way.
<?php /** * * PHP版3DES加解密類 * * 可與java的3DES(DESede)加密方式兼容 * * @Author: Luo Hui (farmer.luo at gmail.com) * * @version: V0.1 2008.12.04 * */ class Crypt3Des { public $key = "01234567890123456789012345678912"; public $iv = "23456789"; //like java: private static byte[] myIV = { 50, 51, 52, 53, 54, 55, 56, 57 }; //加密 public function encrypt($input) { $input = $this->padding( $input ); $key = base64_decode($this->key); $td = mcrypt_module_open( MCRYPT_3DES, '', MCRYPT_MODE_CBC, ''); //使用MCRYPT_3DES算法,cbc模式 mcrypt_generic_init($td, $key, $this->iv); //初始處理 $data = mcrypt_generic($td, $input); //加密 mcrypt_generic_deinit($td); //結(jié)束 mcrypt_module_close($td); $data = $this->removeBR(base64_encode($data)); return $data; } //解密 public function decrypt($encrypted) { $encrypted = base64_decode($encrypted); $key = base64_decode($this->key); $td = mcrypt_module_open( MCRYPT_3DES,'',MCRYPT_MODE_CBC,''); //使用MCRYPT_3DES算法,cbc模式 mcrypt_generic_init($td, $key, $this->iv); //初始處理 $decrypted = mdecrypt_generic($td, $encrypted); //解密 mcrypt_generic_deinit($td); //結(jié)束 mcrypt_module_close($td); $decrypted = $this->removePadding($decrypted); return $decrypted; } //填充密碼,填充至8的倍數(shù) public function padding( $str ) { $len = 8 - strlen( $str ) % 8; for ( $i = 0; $i < $len; $i++ ) { $str .= chr( 0 ); } return $str ; } //刪除填充符 public function removePadding( $str ) { $len = strlen( $str ); $newstr = ""; $str = str_split($str); for ($i = 0; $i < $len; $i++ ) { if ($str[$i] != chr( 0 )) { $newstr .= $str[$i]; } } return $newstr; } //刪除回車和換行 public function removeBR( $str ) { $len = strlen( $str ); $newstr = ""; $str = str_split($str); for ($i = 0; $i < $len; $i++ ) { if ($str[$i] != '\n' and $str[$i] != '\r') { $newstr .= $str[$i]; } } return $newstr; } } //test $input = "1qaz2ws"; echo "plainText:" . $input."<br/>"; $crypt = new Crypt3Des(); echo "Encode:".$crypt->encrypt($input)."<br/>"; echo "Decode:".$crypt->decrypt($crypt->encrypt($input)); ?>
You don’t have to look at the code, just look at the sentence inside: $td = mcrypt_module_open( MCRYPT_3DES, '', MCRYPT_MODE_CBC, ''); He was the one who reported the error.
I searched for a lot of solutions, the correct method should be (only for Windows system):
This error occurs when using the function mcrypt_module_open for decryption when libmcrypt.dll is missing on the server side running php.
Make the following settings on the server to solve the problem.
Go to the Internet to download a PHP mcrypt module installation package. You only need the libmcrypt.dll file (generally downloaded from the official website and already available in the PHP directory)
1. Copy libmcrypt.dll to the system32 directory or the extensions directory under the php installation directory
2. Copy libmcrypt.dll to the bin directory of the apache installation directory
3. Find the php.ini file in the windows directory and open it
4. Find; Directory in which the loadable extensions (modules) reside.
extension_dir = "./" For example: extension_dir = "D:php5ext"
These two lines must ensure that libmcrypt.dll can be found in the directory pointed by extension_dir, or there is libmcrypt.dll in the system path
5. Find the line ;extension=php_mcrypt.dll and the line ;extension=php_iconv.dll (I don’t have mine, so I omitted it) under the Windows Extensions item, and remove the semicolon in front of it
ps: I just started looking at the solutions online. Some said to modify php.ini in the php installation directory, but it was useless after modification. Be sure to modify php.ini in the windows directory!

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

TostaycurrentwithPHPdevelopmentsandbestpractices,followkeynewssourceslikePHP.netandPHPWeekly,engagewithcommunitiesonforumsandconferences,keeptoolingupdatedandgraduallyadoptnewfeatures,andreadorcontributetoopensourceprojects.First,followreliablesource

PHPbecamepopularforwebdevelopmentduetoitseaseoflearning,seamlessintegrationwithHTML,widespreadhostingsupport,andalargeecosystemincludingframeworkslikeLaravelandCMSplatformslikeWordPress.Itexcelsinhandlingformsubmissions,managingusersessions,interacti

TosettherighttimezoneinPHP,usedate_default_timezone_set()functionatthestartofyourscriptwithavalididentifiersuchas'America/New_York'.1.Usedate_default_timezone_set()beforeanydate/timefunctions.2.Alternatively,configurethephp.inifilebysettingdate.timez

TovalidateuserinputinPHP,usebuilt-invalidationfunctionslikefilter_var()andfilter_input(),applyregularexpressionsforcustomformatssuchasusernamesorphonenumbers,checkdatatypesfornumericvalueslikeageorprice,setlengthlimitsandtrimwhitespacetopreventlayout

ThePhpfunctionSerialize () andunserialize () AreusedtoconvertcomplexdaTastructdestoresintostoraSandaBackagain.1.Serialize () c OnvertsdatalikecarraysorobjectsraystringcontainingTypeandstructureinformation.2.unserialize () Reconstruct theoriginalatataprom

You can embed PHP code into HTML files, but make sure that the file has an extension of .php so that the server can parse it correctly. Use standard tags to wrap PHP code, insert dynamic content anywhere in HTML. In addition, you can switch PHP and HTML multiple times in the same file to realize dynamic functions such as conditional rendering. Be sure to pay attention to the server configuration and syntax correctness to avoid problems caused by short labels, quotation mark errors or omitted end labels.

The key to writing clean and easy-to-maintain PHP code lies in clear naming, following standards, reasonable structure, making good use of comments and testability. 1. Use clear variables, functions and class names, such as $userData and calculateTotalPrice(); 2. Follow the PSR-12 standard unified code style; 3. Split the code structure according to responsibilities, and organize it using MVC or Laravel-style catalogs; 4. Avoid noodles-style code and split the logic into small functions with a single responsibility; 5. Add comments at key points and write interface documents to clarify parameters, return values ??and exceptions; 6. Improve testability, adopt dependency injection, reduce global state and static methods. These practices improve code quality, collaboration efficiency and post-maintenance ease.

Yes,youcanrunSQLqueriesusingPHP,andtheprocessinvolveschoosingadatabaseextension,connectingtothedatabase,executingqueriessafely,andclosingconnectionswhendone.Todothis,firstchoosebetweenMySQLiorPDO,withPDObeingmoreflexibleduetosupportingmultipledatabas
