From Leo's Notes
Last edited on 30 May 2017, at 21:13.

Basic Usage

First create a curl instance using the curl_init function. Second, define any options using the curl_setopt function. Finally, fire the request using curl_exec and close with curl_close.


// create a new cURL resource
$c = curl_init();

// Set request options
curl_setopt($c, CURLOPT_URL, "");
curl_setopt($c, CURLOPT_HEADER, 0);

// Run the request

// close the resource

curl_exec will by default output the contents of the request. The request above will not provide the HTTP request with a user agent string and will show up as an empty string on the remote host.

Setting Headers

Something a little more advanced

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "" . $date);
curl_setopt($ch, CURLOPT_REFERER, "");
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

$html = curl_exec($ch);