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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13433946/
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 05:25:40  来源:igfitidea点击:

How to check if curl is enabled or disabled

php

提问by Reham Fahmy

Possible Duplicate:
Writing a function in php

可能的重复:
在 php 中编写一个函数

I'm using the following code

我正在使用以下代码

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

this can get it enabled or disabled

这可以启用或禁用它

but I would like to make as function say function name is _iscurl

但我想作为函数说函数名称是 _iscurl

then I can call it as following any where in my website code

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

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

almost same as my previous question check if allow_url_fopen is enabled or not

与我之前的问题几乎相同,检查是否启用了allow_url_fopen

回答by John V.

Just return your existing check from a function.

只需从函数返回您现有的支票。

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

回答by Amit Pandey

<?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

只需搜索 curl

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

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

回答by Alex S

var_dump(extension_loaded('curl'));

回答by manish1706

you can check by putting these code in php file.

您可以通过将这些代码放在 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";
}

OR

或者

var_dump(extension_loaded('curl'));

回答by bikash shrestha

Hope this helps.

希望这可以帮助。

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

回答by Samuel Cook

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

您始终可以创建一个新页面并使用phpinfo(). 向下滚动到 curl 部分,看看它是否已启用。

回答by Channaveer Hakari

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');