0

I am trying to get the contents of a webpage and echo it out over a proxy but the code below doesn't return anything (I have tried several URLs, same result). Thoughts on what could cause this? I also tried swapping proxy addresses... same no result:

function url_get_contents2 ($url) {
    $proxy = '###.###.###.###:8080';
    //$proxyauth = 'user:password';

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL,$url);
    curl_setopt($ch, CURLOPT_PROXY, $proxy);
    //curl_setopt($ch, CURLOPT_PROXYUSERPWD, $proxyauth);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_HEADER, 1);
    $curl_scraped_page = curl_exec($ch);
    curl_close($ch);
    
    return $curl_scraped_page;
}

echo url_get_contents2("https://www.whatismybrowser.com/");
AAA
  • 2,388
  • 9
  • 32
  • 47
  • I used this post as a starting point: https://stackoverflow.com/questions/5211887/how-to-use-curl-via-a-proxy – AAA Sep 18 '20 at 23:27
  • I guess step one would be debugging the code, check for error messages. – miken32 Sep 18 '20 at 23:40
  • @miken32 thanks for the insight, I don’t see any errors - how are you seeing an error? – AAA Sep 19 '20 at 01:08
  • Well you say it's not returning anything, it sounds like that is not the behaviour you're expecting. This is either caused by some sort of error, or the server is not returning what you expect. – miken32 Sep 21 '20 at 17:27

0 Answers0