Using a proxy server with fopen

fopen, php, proxy, stream

Solution

You can use the Proxy-Authorization in the `$context` if the proxy requires authentication.Example from PHP.Net:

$opts= array(
                 'http' => array( 
                 'proxy' => 'tcp://proxyip:8080', 
                 'header' => array( 
                                     "Proxy-Authorization: Basic $auth" 
                                  ) 
                ) 
); 
$context = stream_context_create($opts); 

Also,I think you cannot change tcp to http in `tcp://192.168.10.10:80` since what the proxy does is establishing a TCP connection to another server on behalf of a client then route all the traffic back and forth between the client and the server.Obviously it concerns with TCP(sometimes UDP) instead of HTTP.Http proxies just "understand" the traffic delivered by HTTP protocol.

Problem

I'm trying to use fopen to read a remote file from another website. I want to use a proxy to do this, and as far as I know I can do: ``` $context = stream_context_create(array( 'http' => array( 'proxy' => 'tcp://192.168.10.10:80' // The proxy server address and port ), )); $file = fopen($url, 'r', false, $context) ``` but is there a way to authenticate using a username and password for that proxy? Or am I limited to having to use public proxies? Also, the proxy definition is `tcp://192.168.10.10:80`. If I wanted to use a HTTP proxy, am I free to just change it to `http://192.168.10.10:80`? Thanks.

Original source