0

I am on my college network which uses a proxy server with authentication to browse the internet.

I am trying to fetch the data from a web-site using html_get_contents, but running the script on the terminal gives me this error:

PHP Warning: file_get_contents(http://www.google.com/): failed to open stream: Network is unreachable in /var/www/api/get_contents.php on line 2

The code I am using to do this is as follows:

<?php
    $contents = file_get_contents("http://www.google.com/");
    echo $contents;
?>

It seems like I need to set the proxy for php to get the contents, where do I set this?

SomeShinyObject
  • 7,581
  • 6
  • 39
  • 59
jobin
  • 2,600
  • 7
  • 32
  • 59

1 Answers1

1

Use curl.

In http://www.php.net/manual/en/function.curl-setopt.php set options: "CURLOPT_PROXYAUTH", "CURLOPT_PROXYPORT", "CURLOPT_PROXYTYPE"

AlexeyKa
  • 558
  • 3
  • 9
  • Hey, thanks a lot @AlexeyKa, I wanted to use `file_get_contents` for now and got the answer from the question here: http://stackoverflow.com/questions/5139459/file-get-contents-behind-a-isa-proxy-under-apache?rq=1 – jobin Apr 01 '13 at 15:01