authenticate throw squid proxy (PHP socket)
I'd like to create开发者_如何转开发 a program which could authenticate throw Squid proxy. I'm using socket in PHP langage
Both built-in streams and the cURL extension have the ability to make requests through a proxy. Using either would be vastly preferable to using a socket directly.
The cURL extension expressly mentions proxy authentication, while streams does not expressly mention it, but accepts the proxy as a URI, so you might be able to use the proto://user:pass@host:port
syntax. I have not tried, and don't know for sure if that works.
I assume that you mean you want to make a HTTP request via a proxy which requires authentication rather than use the authentication method within Squid to validate requests to your webserver.
You just need to set the right values for CURLOPT_PROXYAUTH CURLOPT_PROXYPORT (usually 3128) and CURLOPT_PROXYTYPE (http)
$ch = curl_init();
$opts=array(
CURLOPT_PROXY="squid.example.com",
CURLOPT_PROXYPORT=>3128,
CURLOPT_PROXYTYPE=>CURLPROXY_HTTP,
CURLOPT_PROXYAUTH=>CURLAUTH_BASIC,
CURLOPT_PROXYUSERPWD=>"${username}:${password}",
CURLOPT_URL=>"http://www.example.com/sompage.html");
curl_setopt_array($opts);
curl_exec($ch);
Note that this assumes that the squid is configured for HTTP authentication (rather than session or NTLM based authentication).
You really don't want to do this using sockets in PHP.
HTH
C.
精彩评论