View Full Version : CURL SOCKS Proxies Going To Incorrect URL???

06-25-2010, 03:57 PM
I am attempting to get the script below to connect to a URL but when it connects to a file that I setup that simply echos out the URL being requested it is requesting:


So it is adding the server address before the request URL for some strange reason, whereas the same script using HTTP proxies is connecting just fine.



If I browse directly to the above file it will show me:


CURL Script:

function Return_Content_From_URL_Agent($url,$cookies,$proxy,$port,$loginpassw,$userAgent,$proxytype){
$ch = curl_init();
curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_PROXYPORT, $port);
curl_setopt($ch, CURLOPT_PROXYTYPE, $proxytype);
curl_setopt($ch, CURLOPT_PROXY, $proxy);
if ($loginpassw!="0:0"){
curl_setopt($ch, CURLOPT_PROXYUSERPWD, $loginpassw);
curl_setopt($ch, CURLOPT_VERBOSE, 0);
curl_setopt($ch, CURLOPT_COOKIEJAR, str_replace('\\','/',dirname(__FILE__)).'/cookies/'.$cookies.'.txt');
curl_setopt($ch, CURLOPT_COOKIEFILE, str_replace('\\','/',dirname(__FILE__)).'/cookies/'.$cookies.'.txt');
$html= curl_exec($ch);
$err = 0;
$err = curl_errno($ch);
if ($err!=0){
echo "<b>Error Connecting To Proxy. CURL Error: $err.</b><br />";
$newlines = array("\t","\n","\r","\x20\x20","\0","\x0B");
$content = str_replace($newlines, "", html_entity_decode($html));
return $content;
$proxy = "xxx";
$port = "xxx";
$loginpassw = "0:0";
$useragent = "Mozilla/5.0 (Windows NT 5.0; U; en-GB; rv:1.8.1) Gecko/20061208 Firefox/2.0.0 Opera 9.61";
$proxytype = "CURLPROXY_SOCKS5";
$content = Return_Content_From_URL_Agent("http://www.mysite.com/test.php","cookies",$proxy,$port,$loginpassw,$useragent,$proxytype);
echo "<textarea>$content</textarea>";

Yet again, if I change the request URL to:


(Note the https://) it works just fine.

I cannot work out for the life of me why https:// will work fine and http:// wont when exactly the same script on HTTP proxies works just fine.

Any ideas?

06-26-2010, 09:09 AM
Chris, that does not read well to me - so can I just clarify and ask a couple of supplementary questions?

If you call your 'echoback' script that repeats the called URL/I directly from a browser it gives the correct results as in:


But if you call it with your Curl script that makes use of a socks5 proxy you get:


What if you call it with your Curl script without specifying a socks5 proxy? What happens then? What is the target server (Apache/IIS/other)?

I note your comment about it working with https but failing with http. Is your SOCKS5 proxy actually handling the https request as a 'man in the middle' or is it bypassed for https?

I've played with that code Chris and I can't recreate the doubling of the host. My logical guess is *something* is appending the server name to the URI {$_SERVER["REQUEST_URI"]} directive. I guess a URI could quite legally include the server name but it begs the question 'why not consistently?'