How to check if curl is enabled or disabled

Php

Php Problem Overview


> Possible Duplicate:
> https://stackoverflow.com/questions/8786428/writing-a-function-in-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

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

Php Solutions


Solution 1 - Php

Just return your existing check from a function.

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

Solution 2 - Php

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

Solution 3 - Php

var_dump(extension_loaded('curl'));

Solution 4 - Php

Hope this helps.

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

Solution 5 - Php

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

Solution 6 - Php

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

Solution 7 - Php

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionReham FahmyView Question on Stackoverflow
Solution 1 - PhpJohn V.View Answer on Stackoverflow
Solution 2 - PhpAmit PandeyView Answer on Stackoverflow
Solution 3 - PhpAlex SView Answer on Stackoverflow
Solution 4 - Phpbikash shresthaView Answer on Stackoverflow
Solution 5 - Phpmanish1706View Answer on Stackoverflow
Solution 6 - PhpSamuel CookView Answer on Stackoverflow
Solution 7 - PhpChannaveer HakariView Answer on Stackoverflow