I'm trying to get the content of a site through cURL, it work just fine on terminal, however it doesn't work with PHP, below is my code.
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://example.com/",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => array(
"cache-control: no-cache",
"referer: https://www.example.com/something",
"user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:52.0) Gecko/20100101 Firefox/52.0"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
I have tried the answer on this question, but it didn't work for me, I got the same error..
I have also tried including the settings below in my code, it didn't work either.
CURLOPT_SSL_VERIFYHOST => false,
CURLOPT_SSL_VERIFYPEER => false,
I'm using Nginx and Laravel, my PHP version is 7.1.2, my cURL version is 7.51.0 and I'm on macOS Sierra 10.12.3.
How can I get it working?