I've been having a lot of trouble connecting a network proxy. I've already tried several setups, but none of them have worked. The closest one has returned a "HTTP/1.1 407 Proxy Authentication Required [Proxy-Authenticate]" error even though I've already authenticated.
Here is the code I'm using:
<?php
// Edit the four values below
$PROXY_HOST = "proxy.det.nsw.edu.au"; // Proxy server address
$PROXY_PORT = "8080"; // Proxy server port
$PROXY_USER = "USERNAME"; // Username
$PROXY_PASS = "PASSWORD"; // Password
// Username and Password are required only if your proxy server needs basic authentication
$auth = base64_encode("$PROXY_USER:$PROXY_PASS");
stream_context_set_default(
array(
'http' => array(
'proxy' => "tcp://$PROXY_HOST:$PROXY_PORT",
'request_fulluri' => true,
'header' => "Proxy-Authorization: Basic $auth"
// Remove the 'header' option if proxy authentication is not required
)
)
);
$targetURL = "http://stackoverflow.com/questions/17111112/using-get-headers-with-a-proxy";
print_r(get_headers($targetURL, 1));
echo ("<br><br>");
$result = file_get_contents($targetURL);
?>
And here is the return from the proxy:
Array ( [0] => HTTP/1.1 407 Proxy Authentication Required [Proxy-Authenticate] => Array ( [0] => NEGOTIATE [1] => NTLM ) [Cache-Control] => no-cache [Pragma] => no-cache [Content-Type] => text/html; charset=utf-8 [Proxy-Connection] => close [Set-Cookie] => BCSI-CS-47afdfff6410962d=2; Path=/ [Connection] => close [Content-Length] => 653 )
Warning: file_get_contents(http://stackoverflow.com/questions/17111112/using-get-headers-with-a-proxy): failed to open stream: HTTP request failed! HTTP/1.1 407 Proxy Authentication Required in C:\inetpub\wwwroot\sites\phpProxyTest.php on line 36
If it helps, I'm trying to authenticate users against the proxy to see if they are valid user so I only need a Yes/No response from the proxy for this. Unfortunately, I don't have access to an admin login or any other parts of the proxy, so getting the users directly isn't an option. Any help would be appreciated, and please ask if you need more info.