tags:

views:

34

answers:

2

hello,

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

A: 

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.

Charles
yeah, i'd like to use directly socket in my program intead of calling curl extensions.i don't know what to receive, and what to send to authenticate throw the proxy ...
You really don't want to use sockets when someone has already done all the hard work for you in creating a library.
Charles
A: 

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.

symcbean