


PHP加密3DES报错 Call to undefined function: mcrypt_module_open() 的解决办法
PHP加密3DES报错 Call to undefined function: mcrypt_module_open() 的解决方法
我也是PHP新手,通过w3cschool了解了一下php基本原理之后就开写了。但仍是菜鸟。
先不管3DES加密的方法对不对,方法都是网上的,在运行的时候报了个错,把小弟整死了。找来找去终于自己摸出了方法。
<span style="color: #000000;">php</span><span style="color: #008000;">/*</span><span style="color: #008000;">** * PHP版3DES加解密类** 可与java的3DES(DESede)加密方式兼容** @Author: Luo Hui (farmer.luo at gmail.com)** @version: V0.1 2008.12.04*</span><span style="color: #008000;">*/</span><span style="color: #0000ff;">class</span><span style="color: #000000;"> Crypt3Des{ </span><span style="color: #0000ff;">public</span> <span style="color: #800080;">$key</span> = "01234567890123456789012345678912"<span style="color: #000000;">; </span><span style="color: #0000ff;">public</span> <span style="color: #800080;">$iv</span> = "23456789"; <span style="color: #008000;">//</span><span style="color: #008000;">like java: private static byte[] myIV = { 50, 51, 52, 53, 54, 55, 56, 57 }; //加密</span> <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">function</span> encrypt(<span style="color: #800080;">$input</span><span style="color: #000000;">) { </span><span style="color: #800080;">$input</span> = <span style="color: #800080;">$this</span>->padding( <span style="color: #800080;">$input</span><span style="color: #000000;"> ); </span><span style="color: #800080;">$key</span> = <span style="color: #008080;">base64_decode</span>(<span style="color: #800080;">$this</span>-><span style="color: #008080;">key</span><span style="color: #000000;">); </span><span style="color: #800080;">$td</span> = mcrypt_module_open( MCRYPT_3DES, '', MCRYPT_MODE_CBC, ''<span style="color: #000000;">); </span><span style="color: #008000;">//</span><span style="color: #008000;">使用MCRYPT_3DES算法,cbc模式</span> mcrypt_generic_init(<span style="color: #800080;">$td</span>, <span style="color: #800080;">$key</span>, <span style="color: #800080;">$this</span>-><span style="color: #000000;">iv); </span><span style="color: #008000;">//</span><span style="color: #008000;">初始处理</span> <span style="color: #800080;">$data</span> = mcrypt_generic(<span style="color: #800080;">$td</span>, <span style="color: #800080;">$input</span><span style="color: #000000;">); </span><span style="color: #008000;">//</span><span style="color: #008000;">加密</span> mcrypt_generic_deinit(<span style="color: #800080;">$td</span><span style="color: #000000;">); </span><span style="color: #008000;">//</span><span style="color: #008000;">结束</span> mcrypt_module_close(<span style="color: #800080;">$td</span><span style="color: #000000;">); </span><span style="color: #800080;">$data</span> = <span style="color: #800080;">$this</span>->removeBR(<span style="color: #008080;">base64_encode</span>(<span style="color: #800080;">$data</span><span style="color: #000000;">)); </span><span style="color: #0000ff;">return</span> <span style="color: #800080;">$data</span><span style="color: #000000;">; } </span><span style="color: #008000;">//</span><span style="color: #008000;">解密</span> <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">function</span> decrypt(<span style="color: #800080;">$encrypted</span><span style="color: #000000;">) { </span><span style="color: #800080;">$encrypted</span> = <span style="color: #008080;">base64_decode</span>(<span style="color: #800080;">$encrypted</span><span style="color: #000000;">); </span><span style="color: #800080;">$key</span> = <span style="color: #008080;">base64_decode</span>(<span style="color: #800080;">$this</span>-><span style="color: #008080;">key</span><span style="color: #000000;">); </span><span style="color: #800080;">$td</span> = mcrypt_module_open( MCRYPT_3DES,'',MCRYPT_MODE_CBC,''<span style="color: #000000;">); </span><span style="color: #008000;">//</span><span style="color: #008000;">使用MCRYPT_3DES算法,cbc模式</span> mcrypt_generic_init(<span style="color: #800080;">$td</span>, <span style="color: #800080;">$key</span>, <span style="color: #800080;">$this</span>-><span style="color: #000000;">iv); </span><span style="color: #008000;">//</span><span style="color: #008000;">初始处理</span> <span style="color: #800080;">$decrypted</span> = mdecrypt_generic(<span style="color: #800080;">$td</span>, <span style="color: #800080;">$encrypted</span><span style="color: #000000;">); </span><span style="color: #008000;">//</span><span style="color: #008000;">解密</span> mcrypt_generic_deinit(<span style="color: #800080;">$td</span><span style="color: #000000;">); </span><span style="color: #008000;">//</span><span style="color: #008000;">结束</span> mcrypt_module_close(<span style="color: #800080;">$td</span><span style="color: #000000;">); </span><span style="color: #800080;">$decrypted</span> = <span style="color: #800080;">$this</span>->removePadding(<span style="color: #800080;">$decrypted</span><span style="color: #000000;">); </span><span style="color: #0000ff;">return</span> <span style="color: #800080;">$decrypted</span><span style="color: #000000;">; } </span><span style="color: #008000;">//</span><span style="color: #008000;">填充密码,填充至8的倍数</span> <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">function</span> padding( <span style="color: #800080;">$str</span><span style="color: #000000;"> ) { </span><span style="color: #800080;">$len</span> = 8 - <span style="color: #008080;">strlen</span>( <span style="color: #800080;">$str</span> ) % 8<span style="color: #000000;">; </span><span style="color: #0000ff;">for</span> ( <span style="color: #800080;">$i</span> = 0; <span style="color: #800080;">$i</span> $len; <span style="color: #800080;">$i</span>++<span style="color: #000000;"> ) { </span><span style="color: #800080;">$str</span> .= <span style="color: #008080;">chr</span>( 0<span style="color: #000000;"> ); } </span><span style="color: #0000ff;">return</span> <span style="color: #800080;">$str</span><span style="color: #000000;"> ; } </span><span style="color: #008000;">//</span><span style="color: #008000;">删除填充符</span> <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">function</span> removePadding( <span style="color: #800080;">$str</span><span style="color: #000000;"> ) { </span><span style="color: #800080;">$len</span> = <span style="color: #008080;">strlen</span>( <span style="color: #800080;">$str</span><span style="color: #000000;"> ); </span><span style="color: #800080;">$newstr</span> = ""<span style="color: #000000;">; </span><span style="color: #800080;">$str</span> = <span style="color: #008080;">str_split</span>(<span style="color: #800080;">$str</span><span style="color: #000000;">); </span><span style="color: #0000ff;">for</span> (<span style="color: #800080;">$i</span> = 0; <span style="color: #800080;">$i</span> $len; <span style="color: #800080;">$i</span>++<span style="color: #000000;"> ) { </span><span style="color: #0000ff;">if</span> (<span style="color: #800080;">$str</span>[<span style="color: #800080;">$i</span>] != <span style="color: #008080;">chr</span>( 0<span style="color: #000000;"> )) { </span><span style="color: #800080;">$newstr</span> .= <span style="color: #800080;">$str</span>[<span style="color: #800080;">$i</span><span style="color: #000000;">]; } } </span><span style="color: #0000ff;">return</span> <span style="color: #800080;">$newstr</span><span style="color: #000000;">; } </span><span style="color: #008000;">//</span><span style="color: #008000;">删除回车和换行</span> <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">function</span> removeBR( <span style="color: #800080;">$str</span><span style="color: #000000;"> ) { </span><span style="color: #800080;">$len</span> = <span style="color: #008080;">strlen</span>( <span style="color: #800080;">$str</span><span style="color: #000000;"> ); </span><span style="color: #800080;">$newstr</span> = ""<span style="color: #000000;">; </span><span style="color: #800080;">$str</span> = <span style="color: #008080;">str_split</span>(<span style="color: #800080;">$str</span><span style="color: #000000;">); </span><span style="color: #0000ff;">for</span> (<span style="color: #800080;">$i</span> = 0; <span style="color: #800080;">$i</span> $len; <span style="color: #800080;">$i</span>++<span style="color: #000000;"> ) { </span><span style="color: #0000ff;">if</span> (<span style="color: #800080;">$str</span>[<span style="color: #800080;">$i</span>] != '\n' and <span style="color: #800080;">$str</span>[<span style="color: #800080;">$i</span>] != '\r'<span style="color: #000000;">) { </span><span style="color: #800080;">$newstr</span> .= <span style="color: #800080;">$str</span>[<span style="color: #800080;">$i</span><span style="color: #000000;">]; } } </span><span style="color: #0000ff;">return</span> <span style="color: #800080;">$newstr</span><span style="color: #000000;">; }}</span><span style="color: #008000;">//</span><span style="color: #008000;">test</span><span style="color: #800080;">$input</span> = "1qaz2ws"<span style="color: #000000;">;</span><span style="color: #0000ff;">echo</span> "plainText:" . <span style="color: #800080;">$input</span>."<br>"<span style="color: #000000;">;</span><span style="color: #800080;">$crypt</span> = <span style="color: #0000ff;">new</span><span style="color: #000000;"> Crypt3Des();</span><span style="color: #0000ff;">echo</span> "Encode:".<span style="color: #800080;">$crypt</span>->encrypt(<span style="color: #800080;">$input</span>)."<br>"<span style="color: #000000;">;</span><span style="color: #0000ff;">echo</span> "Decode:".<span style="color: #800080;">$crypt</span>->decrypt(<span style="color: #800080;">$crypt</span>->encrypt(<span style="color: #800080;">$input</span><span style="color: #000000;">));</span>?>
代码可以不看,就看里面的一句:$td = mcrypt_module_open( MCRYPT_3DES, '', MCRYPT_MODE_CBC, '');报错的就是他。
我搜寻了一大堆解决方法,正确的方法应该是(仅用于windows系统哦):
当运行php的服务器端缺少libmcrypt.dll时使用函数mcrypt_module_open进行解密会出现此错误。
在服务器上做如下设置可解决。
到网上下载一个php的mcrypt模块安装包,只需要libmcrypt.dll文件即可(一般官网上下载的,php目录下已经有的)
1.将libmcrypt.dll复制到system32目录或php安装目录下的extensions目录下
2.将libmcrypt.dll复制到apache安装目录的bin目录下
3.到windows目录下找到php.ini文件,打开它
4.找到; Directory in which the loadable extensions (modules) reside.
extension_dir = "./" 如:extension_dir = "D:\php5\ext"
这两行,要使extension_dir指向的目录下能找到libmcrypt.dll,或系统path下有libmcrypt.dll
5.找到;Windows Extensions 项下面的;extension=php_mcrypt.dll这一行和;extension=php_iconv.dll(我的没有,省略了)这两行,去掉前面的分号
ps:刚开始看网上的解决方法,有的说修改php安装目录下的php.ini,但是修改后是没用的。一定要修改windows目录下的php.ini!

La définition des paramètres de cookie de session dans PHP peut être réalisée via la fonction Session_Set_COOKIE_PARAMS (). 1) Utilisez cette fonction pour définir des paramètres, tels que le temps d'expiration, le chemin, le nom de domaine, le drapeau de sécurité, etc.; 2) Appelez session_start () pour que les paramètres prennent effet; 3) Ajuster dynamiquement les paramètres en fonction des besoins, tels que l'état de connexion de l'utilisateur; 4) Faites attention à la définition de drapeaux sécurisés et httponly pour améliorer la sécurité.

L'objectif principal de l'utilisation de sessions en PHP est de maintenir l'état de l'utilisateur entre différentes pages. 1) La session est lancée via la fonction session_start (), créant un ID de session unique et le stockant dans le cookie utilisateur. 2) Les données de session sont enregistrées sur le serveur, permettant de passer les données entre différentes demandes, telles que l'état de connexion et le contenu du panier.

Comment partager une session entre les sous-domaines? Implémenté en définissant des cookies de session pour les noms de domaine communs. 1. Définissez le domaine du cookie de session sur .example.com côté serveur. 2. Choisissez la méthode de stockage de session appropriée, telle que la mémoire, la base de données ou le cache distribué. 3. Passez l'ID de session via des cookies, et le serveur récupère et met à jour les données de session en fonction de l'ID.

HTTPS améliore considérablement la sécurité des sessions en cryptant la transmission des données, en empêchant les attaques de l'homme dans le milieu et en fournissant l'authentification. 1) Transmission de données chiffrées: HTTPS utilise le protocole SSL / TLS pour crypter les données pour garantir que les données ne sont pas volées ou falsifiées pendant la transmission. 2) Empêcher les attaques de l'homme au milieu: via le processus de poignée de main SSL / TLS, le client vérifie le certificat de serveur pour assurer la légitimité de la connexion. 3) Fournir l'authentification: HTTPS garantit que la connexion est un serveur légitime et protège l'intégrité et la confidentialité des données.

Ce qui est encore populaire, c'est la facilité d'utilisation, la flexibilité et un écosystème fort. 1) La facilité d'utilisation et la syntaxe simple en font le premier choix pour les débutants. 2) étroitement intégré au développement Web, excellente interaction avec les demandes HTTP et la base de données. 3) L'énorme écosystème fournit une multitude d'outils et de bibliothèques. 4) La nature active et la nature open source les adaptent à de nouveaux besoins et tendances technologiques.

PHP et Python sont tous deux des langages de programmation de haut niveau qui sont largement utilisés dans le développement Web, le traitement des données et les tâches d'automatisation. 1.Php est souvent utilisé pour créer des sites Web dynamiques et des systèmes de gestion de contenu, tandis que Python est souvent utilisé pour créer des cadres Web et une science des données. 2.PHP utilise Echo pour sortir du contenu, Python utilise l'impression. 3. Les deux prennent en charge la programmation orientée objet, mais la syntaxe et les mots clés sont différents. 4. PHP prend en charge la conversion de type faible, tandis que Python est plus strict. 5. L'optimisation des performances PHP comprend l'utilisation de la programmation OPCACH et asynchrone, tandis que Python utilise la programmation CPROFILE et asynchrone.

PHP est principalement la programmation procédurale, mais prend également en charge la programmation orientée objet (POO); Python prend en charge une variété de paradigmes, y compris la POO, la programmation fonctionnelle et procédurale. PHP convient au développement Web, et Python convient à une variété d'applications telles que l'analyse des données et l'apprentissage automatique.

PHP est originaire en 1994 et a été développé par Rasmuslerdorf. Il a été utilisé à l'origine pour suivre les visiteurs du site Web et a progressivement évolué en un langage de script côté serveur et a été largement utilisé dans le développement Web. Python a été développé par Guidovan Rossum à la fin des années 1980 et a été publié pour la première fois en 1991. Il met l'accent sur la lisibilité et la simplicité du code, et convient à l'informatique scientifique, à l'analyse des données et à d'autres domaines.


Outils d'IA chauds

Undresser.AI Undress
Application basée sur l'IA pour créer des photos de nu réalistes

AI Clothes Remover
Outil d'IA en ligne pour supprimer les vêtements des photos.

Undress AI Tool
Images de déshabillage gratuites

Clothoff.io
Dissolvant de vêtements AI

Video Face Swap
Échangez les visages dans n'importe quelle vidéo sans effort grâce à notre outil d'échange de visage AI entièrement gratuit !

Article chaud

Outils chauds

PhpStorm version Mac
Le dernier (2018.2.1) outil de développement intégré PHP professionnel

ZendStudio 13.5.1 Mac
Puissant environnement de développement intégré PHP

Version Mac de WebStorm
Outils de développement JavaScript utiles

Navigateur d'examen sécurisé
Safe Exam Browser est un environnement de navigation sécurisé permettant de passer des examens en ligne en toute sécurité. Ce logiciel transforme n'importe quel ordinateur en poste de travail sécurisé. Il contrôle l'accès à n'importe quel utilitaire et empêche les étudiants d'utiliser des ressources non autorisées.

Bloc-notes++7.3.1
Éditeur de code facile à utiliser et gratuit