curl

The cURL libraries provide a nice interface for file transfers to and from a webserver.

they have support for a wide variety of protocols (like https) giving them an edge over built-in PHP functions

like fsockopen()

The libraries are thread safe ,IPv6 compatible ,and will work with all technology…

cURL is use to fetch data or make a secure payment gateway

to fetch data from a remote server we can use this function to fetch html data…

cURL request to remote server using PHP function

is here

function gethtmldata($url) {
$url = str_replace(" ", '%20', $url);
fopen("cookies.txt", "w");
$parts = parse_url($url);
$host = $parts['host'];
$ch = curl_init($url);
$header = Array('Connection:keep-alive',
'Proxy-Connection: Close',
'User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1017.2 Safari/535.19',
'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Accept-Language: en-US,en;q=0.8',
'Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3',
'Connection: Close');
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0);
curl_setopt($ch, CURLOPT_COOKIESESSION, true);
curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookies.txt');
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookies.txt');
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_USERAGENT, $_REQUEST['HTTP_USER_AGENT']);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
$result = curl_exec($ch);
curl_close($ch);
return $result;
}

let’s take an example to fetch html data from a web server by cURL using this function

<?php

$htmldata=gethtmldata(“https://yashpalsinghblog.com”);

echo $htmldata;

?>

output:

Leave a Reply

Your email address will not be published. Required fields are marked *