Skip to content

Instantly share code, notes, and snippets.

@DWboutin
Last active July 2, 2018 08:14
Show Gist options
  • Save DWboutin/8827402 to your computer and use it in GitHub Desktop.
Save DWboutin/8827402 to your computer and use it in GitHub Desktop.
PHP Curl get content
<?php
$header = array('Accept-Language: en');
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
$httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
$data = curl_exec($curl);
curl_close($curl);
if($httpCode == 200) {
return $data;
}
?>
@h4cc
Copy link

h4cc commented Jan 17, 2016

These lines need to be switched like this, because there cant ba a httpCode before the request was executed.

$data = curl_exec($curl);
$httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment