I want to ask something make me confuse. I'am using CURL to get html code from this link
echo set_user_agent_grab("https://www.bandros.co.id/produk/dress-atasan-baju-rajut-wanita-sad-500");
And This is my function
function set_user_agent_grab($link){
$headers = ["text/html; charset=UTF-8"];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $link);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/533.2 (KHTML, like Gecko) Chrome/5.0.342.3 Safari/533.2');
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_MAXREDIRS, 10);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_ENCODING, 'gzip');
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
The problem, sometimes i got return empty, i dont know this is from my server or from the site protection with i dont know, please tell me, thank you.
$chis undefinedvar_dump(curl_getinfo($ch)),var_dump(curl_errno($ch))andvar_dump(curl_error($ch))after callingcurl_exec()may give you some insight, at the moment you're not looking at any response state information, just the body.var_dumps suggested by @Scuzzy in the comment above to at least track on what occasion it returns empty. I believe this can be the target server did not want to answer your request.