PDA

View Full Version : what is curl in php example



vikas Industries
06-24-2015, 10:41 AM
what is curl in php example

techpro
01-20-2016, 10:16 AM
cURL is a way you can hit a URL from your code to get a html response from it. cURl library enable to make Http requests in PHP and to use cURL function in PHP install libcurl package (For PHP 4.2.3, Install libcurl version 7.9.0 or higher | For PHP 4.3.0 install libcurl version 7.9.8 or higher | For PHP 5.0.0 install libcurl version 7.9.8 or higher)

Learn more at http://php.net/manual/en/book.curl.php

Kristinperry
01-20-2016, 12:57 PM
cURL is a library that gives you a chance to make HTTP asks for in PHP. All that you have to think about it (and most different expansions) can be found in the PHP manual. Keeping in mind the end goal to utilize PHP's cURL capacities you have to introduce the » libcurl bundle. PHP requires that you utilize libcurl 7.0.2-beta or higher.

JasmineEmans
03-02-2017, 07:12 AM
A command line tool for getting or sending files using URL syntax.

jackwilliam
07-27-2017, 05:16 PM
PHP Curl tutorial with example. In this tutorial we will explore what is curl, how to use curl in php. Tutorial is for beginner to advance.

kumkum
08-26-2020, 05:26 PM
Hi,
I know this is old post but i want to add PHP CURL example in this post.
I hope this post is useful for all members.

What is CURL?
cURL is a PHP extension, that allows us to receive and send information via the URL syntax. By doing so, cURL makes it easy to communicate between different websites and domains.


<?php

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 <br><br><br>";
} else {
echo "cURL is NOT <span style=\"color:red\">installed</span> on this server";
}


function isExtensionLoaded($extension_name){
return extension_loaded($extension_name);
}
echo isExtensionLoaded('curl');
echo isExtensionLoaded('gd');



echo " <br><br><br>";

function nxs_cURLTest($url, $msg, $testText){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.73 Safari/537.36");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
$response = curl_exec($ch);
$errmsg = curl_error($ch);
$cInfo = curl_getinfo($ch);
curl_close($ch);
echo "Testing ... ".$url." - ".$cInfo['url']."<br />";
if (stripos($response, $testText)!==false)
echo "....".$msg." - OK<br />";
else
{
echo "....<b style='color:red;'>".$msg." - Problem</b><br /><pre>";
print_r($errmsg);
print_r($cInfo);
print_r(htmlentities($response));
echo "</pre>There is a problem with cURL. You need to contact your server admin or hosting provider.";
}
}
nxs_cURLTest("http://rediff.com", "HTTP to Rediff", "REDIFF");

echo " <br><br><br>";
echo phpinfo();

?>

kumkum
05-03-2021, 03:54 PM
Hi,
I know this is old post but i want to add PHP CURL example in this post.
I hope this post is useful for all members.

What is CURL?
cURL is a PHP extension, that allows us to receive and send information via the URL syntax. By doing so, cURL makes it easy to communicate between different websites and domains.


<?php

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 <br><br><br>";
} else {
echo "cURL is NOT <span style=\"color:red\">installed</span> on this server";
}


function isExtensionLoaded($extension_name){
return extension_loaded($extension_name);
}
echo isExtensionLoaded('curl');
echo isExtensionLoaded('gd');



echo " <br><br><br>";

function nxs_cURLTest($url, $msg, $testText){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.73 Safari/537.36");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
$response = curl_exec($ch);
$errmsg = curl_error($ch);
$cInfo = curl_getinfo($ch);
curl_close($ch);
echo "Testing ... ".$url." - ".$cInfo['url']."<br />";
if (stripos($response, $testText)!==false)
echo "....".$msg." - OK<br />";
else
{
echo "....<b style='color:red;'>".$msg." - Problem</b><br /><pre>";
print_r($errmsg);
print_r($cInfo);
print_r(htmlentities($response));
echo "</pre>There is a problem with cURL. You need to contact your server admin or hosting provider.";
}
}
nxs_cURLTest("http://rediff.com", "HTTP to Rediff", "REDIFF");

echo " <br><br><br>";
echo phpinfo();

?>


You can check CURL (https://hoststud.com/resources/linux-curl-command.52/) complete example.