PHP curl setopt httpheader not working

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP


PHP curl setopt httpheader not working



I observed network status when loading public website and I try to curl the website.
However, it turns out that the curl result will redirect me to an error page instead to the final page. In this case I try to modify the request headers especially host and referer but then it turned out that the headers are still pointing to localhost.
Besides that, can I "maintain" the modified headers information during the other request processing works in the same page load?


function curlFollow($url){
$handle = curl_init();
$host = parse_url($url,PHP_URL_HOST);
// var_dump($url);exit();
$curlHeaders = array(
"Host: $host",
"Referer: $url",
"User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36",
"Accept: application/json, text/plain, */*",
"Accept-Encoding: gzip, deflate, br",
"Accept-Language: en-US,en;q=0.9",
"Connection: keep-alive",
);
if($url == ""){
die("The incoming url is blank!");
}
$proxyServer = '185.18.141.40:41258';
curl_setopt($handle, CURLOPT_URL, $url); // Set the url
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true); // Set the result output to be a string.
curl_setopt($handle, CURLOPT_PROXY, $proxyServer);
curl_setopt($handle, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, 0); //No SSL verification
curl_setopt($handle, CURLOPT_ENCODING, ''); //Handle all type of encoding
curl_setopt($handle, CURLOPT_AUTOREFERER, true);
curl_setopt($handle, CURLOPT_HTTPHEADER,$curlHeaders);
$output = curl_exec($handle);
echo curl_error($handle);
$response = curl_getinfo($handle);
echo curl_errno($handle);
curl_close($handle);
return $output;
}



php curl result









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Visual Studio Code: How to configure includePath for better IntelliSense results

Spring cloud config client Could not locate PropertySource

Makefile test if variable is not empty