[英]How to check extensions are enabled in PHP.ini via PHP CODE
I want to check the geo_ip
extension in php.ini via PHP CODE 我想通过PHP CODE检查php.ini中的
geo_ip
扩展名
But i dont know, how to check ? 但我不知道,如何检查?
Is any solutions are available to check the extensions are enabled or not in php.ini . 是否有任何解决方案可用于检查php.ini中的扩展名是否已启用。
Thanks in Advance. 提前致谢。
You need use the extension_loaded function of SPL 您需要使用SPL的extension_loaded函数
$sExtensionName = 'geoip';
if (!extension_loaded($sExtensionName)) {
exit("Error extension {$sExtensionName} not loaded");
}
Reference function.extension-loaded.php 参考function.extension-loaded.php
I am not sure what do you mean by via PHP CODE. 我不确定通过PHP CODE是什么意思。
If you are trying to check enabled PHP extension in your web server without using Terminal/SSH or any commands, then you can try the described way to check using your browser. 如果您尝试在不使用终端机/ SSH或任何命令的情况下检查Web服务器中已启用的PHP扩展,则可以尝试使用上述方法检查浏览器。
Create a PHP file(file with .php extension). 创建一个PHP文件(扩展名为.php的文件)。 for example,
checkEnabledExtension.php
例如,
checkEnabledExtension.php
Now edit the file and add the following codes and save it: 现在编辑文件并添加以下代码并保存:
<?php
$extensionName = "mysqli"; // replace mysqli by the extension name your want to check. for example: $extensionName = "geoip"; I am not sure about the name of the geo_ip extension.
echo $extensionName;
if(extension_loaded($extensionName)) { // check extension_loaded() in PHP manual for details
echo ": is Enabled."; // if the extension is enabled this block will run
} else {
echo ": is NOT Enabled."; // this block will run if the extension is not enabled
}
?>
Now upload the file to your web root directory. 现在将文件上传到您的Web根目录。 For example: if your domain name is example.com then upload it to web root/public_html of the example.com
例如:如果您的域名是example.com,则将其上传到example.com的Web根目录/ public_html
Now in your browser go to domain.com/checkEnabledExtension.php
现在在浏览器中转到
domain.com/checkEnabledExtension.php
That is it. 这就对了。 You will see if the extension is enabled or not.
您将看到扩展名是否已启用。
To check a list of all enabled extension: 要检查所有已启用扩展的列表:
use this PHP codes in checkEnabledExtension.php
file to get the list of all enabled php extensions instead of checking a single. 使用
checkEnabledExtension.php
文件中的此PHP代码获取所有已启用的php扩展的列表,而不用检查一个。 Use the same procedures above just use these codes: 使用上面的相同步骤,只需使用以下代码:
<?php
print "<pre>"; print_r(get_loaded_extensions()); print "</pre>"; // this will print a list of all enabled PHP extension
?>
BEST OF LUCK 最好的运气
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.