I have test curl command on Reqbin.com and get correct result.
curl execed on reqbin return exactly result
But when I run php curl code, It return Access Denied error.
Result when run php curl code
This is my code:
<?php
$url = "https://www.freepik.com/premium-vector/green-sketches-vegetables-background_899769.htm";
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$headers = array(
'if-none-match: W/"49cmjzwjsg4y8b"',
"priority: u=0, i",
"sec-ch-ua-mobile: ?0",
"sec-fetch-site: none,",
);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
//for debug only!
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$resp = curl_exec($curl);
curl_close($curl);
var_dump($resp);
?>
What is wrong? Thanks!
The cURL command line comes with a default user agent, adding it to the PHP code can successfully get a return:
curl_setopt($curl, CURLOPT_USERAGENT, 'curl/8.9.1');
BTW your "sec-fetch-site: none,"
header contains an extra comma.