如何检查 curl 是启用还是禁用

  • 本文关键字:启用 curl 何检查 php
  • 更新时间 :
  • 英文 :


可能的重复项:
用 php 编写函数

我正在使用以下代码

echo 'Curl: ', function_exists('curl_version') ? 'Enabled' : 'Disabled';

这可以启用或禁用它

但我想让函数说函数名称是_iscurl

然后我可以在我的网站代码中的任何位置调用它

if (_iscurl()){
  echo "this is enabled"; // will do an action
}else{
  echo "this is disabled"; // will do another action
}

几乎与我上一个问题相同,检查是否启用了allow_url_fopen

只需从函数返回现有检查即可。

function _isCurl(){
    return function_exists('curl_version');
}
<?php
// Script to test if the CURL extension is installed on this server
// Define function to test
function _is_curl_installed() {
    if  (in_array  ('curl', get_loaded_extensions())) {
        return true;
    }
    else {
        return false;
    }
}
// Ouput text to user based on test
if (_is_curl_installed()) {
  echo "cURL is <span style="color:blue">installed</span> on this server";
} else {
  echo "cURL is NOT <span style="color:red">installed</span> on this server";
}
?>

还是一个简单的——

<?
phpinfo();
?>

只需搜索卷曲

来源 - http://www.mattsbits.co.uk/item-164.html

var_dump(extension_loaded('curl'));

希望这有帮助。

<?php
    function _iscurl() {
        return function_exists('curl_version');
    }
?>
你可以

通过把这些代码放在php文件中来检查。

<?php
if(in_array  ('curl', get_loaded_extensions())) {
    echo "CURL is available on your web server";
}
else{
    echo "CURL is not available on your web server";
}

var_dump(extension_loaded('curl'));

您可以随时创建新页面并使用 phpinfo() .向下滚动到卷曲部分,看看它是否已启用。

最好

在项目中使用通用的可重用函数,该函数返回扩展是否加载。您可以使用以下函数来检查 -

function isExtensionLoaded($extension_name){
    return extension_loaded($extension_name);
}

用法

echo isExtensionLoaded('curl');
echo isExtensionLoaded('gd');

最新更新