cURL via PHP

Categories: Programming & Scripting, PHP

Pull the result of a cURL query via PHP.

Useful for parsing JSON APIs

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://URL');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query(array('data' => $data)));
$result = curl_exec($ch);
echo $result . "\n";
«
»