如何检查是否启用或禁用 curl

可能的复制品:
在 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 是否启用一样

283415 次浏览

Just return your existing check from a function.

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

You can always create a new page and use phpinfo(). Scroll down to the curl section and see if it is enabled.

Hope this helps.

<?php
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";
}
?>

or a simple one -

<?
phpinfo();
?>

Just search for curl

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

var_dump(extension_loaded('curl'));

Its always better to go for a generic reusable function in your project which returns whether the extension loaded. You can use the following function to check -

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

Usage

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

you can check by putting these code in php file.

<?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";
}

OR

var_dump(extension_loaded('curl'));