I'm trying to use a proxy to access pages but when I try without the proxy the page give 200 response and I get the data, if I try with proxy I get a 0 response and no data. I have tried many different proxies I've found online. Can you see what I'm doing wrong?
header( 'Cache-Control: max-age=60' );
$url = "https://hidester.com/what-is-my-ip-address";
echo "<br/>Search URL: ".$url."<br/><br/>";
// Get page
get_page($url);
var_dump(get_page($url, "193.202.8.57:8085"));
function get_page($url,$proxy = NULL)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
//curl_setopt($ch, CURLOPT_PROXY, $proxy);
curl_setopt($ch, CURLOPT_HEADER, 0); // return headers 0 no 1 yes
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // return page 1:yes
curl_setopt($ch, CURLOPT_TIMEOUT, 200); // http request timeout 20 seconds
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); // Follow redirects, need this if the url changes
if($proxy !== null)
{
echo "<br/> Trying proxy: {$proxy}";
// no need to specify PROXYPORT again
curl_setopt($ch, CURLOPT_PROXY, $proxy);
// to make the request go through as though proxy didn't exist
curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 0);
}
curl_setopt($ch, CURLOPT_MAXREDIRS, 2); //if http server gives redirection responce
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.7) Gecko/20070914 Firefox/2.0.0.7");
curl_setopt($ch, CURLOPT_COOKIEJAR, "cookies.txt"); // cookies storage / here the changes have been made
curl_setopt($ch, CURLOPT_COOKIEFILE, "cookies.txt");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // false for https
curl_setopt($ch, CURLOPT_ENCODING, "gzip"); // the page encoding
$data = curl_exec($ch); // execute the http request
$info = curl_getinfo($ch);
echo "<br/>Response: {$info["http_code"]} URL: {$info["url"]}<br/>";
curl_close($ch); // close the connection
return $data;
}