authenticate throw squid proxy (PHP socket)

感情迁移 提交于 2020-01-03 01:44:08

问题


I'd like to create a program which could authenticate throw Squid proxy. I'm using socket in PHP langage


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/3125714/authenticate-throw-squid-proxy-php-socket

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!