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

php
2022-08-30 08:05:06

可能的重复:
用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


答案 1

只需从函数返回现有支票即可。

function _isCurl(){
    return function_exists('curl_version');
}

答案 2
<?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


推荐