如何检查 php 中是否存在 mcrypt 扩展名

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25476889/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 17:51:10  来源:igfitidea点击:

How to check if mcrypt extension exists in php

phpfunctionencryptionexistsmcrypt

提问by Heroselohim

I would like to know the simplest and fastest PHP code line to check if mcrypt extension is available/installed.

我想知道最简单和最快的 PHP 代码行来检查 mcrypt 扩展是否可用/安装。

There is a function that encrypts a string and first it requires to check if mcrypt is usable. If not, it will execute an alternative encrypt solution available on the system.

有一个加密字符串的函数,首先它需要检查 mcrypt 是否可用。如果没有,它将执行系统上可用的替代加密解决方案。

Thanks!

谢谢!

回答by Charlotte Dunois

You can use function_existsto check if one of the mcrypt functions exists.

您可以使用function_exists来检查 mcrypt 函数之一是否存在。

if(function_exists('mcrypt_encrypt')) {
    echo "mcrypt is loaded!";
} else {
    echo "mcrypt isn't loaded!";
}

Edit 30.07.2016:
Since my answer still gets a few upvotes from time to time, I benchmarked the performance of mine and Cristi Draghici's answers. The conclusion is, that function_existsis a bit faster than extension_loaded. https://3v4l.org/So4Ep

2016
年 7 月 30 日编辑:由于我的回答仍然不时获得一些赞成票,因此我对我的回答和 Cristi Draghici 的回答的表现进行了基准测试。结论是,这function_exists比 快一点extension_loadedhttps://3v4l.org/So4Ep

回答by Cristi Draghici

You can also use extension_loaded():

您还可以使用 extension_loaded():

if (extension_loaded('mcrypt')) {
    echo "mcrypt is loaded!";
} else {
    echo "mcrypt isn't loaded!";
}

回答by Mike Mcgrath

If you are using a development environment like XXAMP, or WAMP, there should be a default "phpinfo" page. For example, in XXAMP it would be:

如果您使用的是 XXAMP 或 WAMP 之类的开发环境,则应该有一个默认的“phpinfo”页面。例如,在 XXAMP 中,它将是:

http://localhost/dashboard/phpinfo.php

http://localhost/dashboard/phpinfo.php

You can also achieve this same screen by viewing a php file that has: phpinfo(); somewhere in the code.

您还可以通过查看具有以下内容的 php 文件来实现相同的屏幕: phpinfo(); 代码中的某处。

In this screen, simply search for the string "mcrypt support". If installed, you will see a box that says "enabled".

在此屏幕中,只需搜索字符串“mcrypt support”。如果已安装,您将看到一个显示“已启用”的框。