Wordpress Themes - Find services - Property in Qatar - Reference 2007 - Wordpress Themes

PDA

View Full Version : cURL/Proxy Trouble...


chatmasta
Jul 4th 2007, 2:26 pm
Hey,

I'm using a modified version of a friend's cURL class. I'm trying to build proxy support into it, but for some reason the page just DOESN'T LOAD. Here's what curl says:

array(19) { ["url"]=> string(22) "http://whatismyip.com/" ["http_code"]=> int(0) ["header_size"]=> int(0) ["request_size"]=> int(0) ["filetime"]=> int(0) ["ssl_verify_result"]=> int(0) ["redirect_count"]=> int(0) ["total_time"]=> float(0) ["namelookup_time"]=> float(0) ["connect_time"]=> float(0) ["pretransfer_time"]=> float(0) ["size_upload"]=> float(0) ["size_download"]=> float(0) ["speed_download"]=> float(0) ["speed_upload"]=> float(0) ["download_content_length"]=> float(0) ["upload_content_length"]=> float(0) ["starttransfer_time"]=> float(0) ["redirect_time"]=> float(0) }

When I take out the parameters I'm using to make it support a proxy, it does work. I should note that this happens with every proxy I've tried. Also, it may help to know that cURL is enabled with SSL fine and dandy.

libcurl/7.15.3 OpenSSL/0.9.7a zlib/1.2.3 libidn/0.5.6

Here's the class. The marked parts are what I'm dealing with now.

class Curl
{
function setup()
{
$cookieJar = 'cookies.txt';
curl_setopt($this->curl, CURLOPT_COOKIEJAR, $cookieJar);
curl_setopt($this->curl, CURLOPT_COOKIEFILE, $cookieJar);
curl_setopt($this->curl, CURLOPT_AUTOREFERER, true);
curl_setopt($this->curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($this->curl, CURLOPT_RETURNTRANSFER, 1);

/**************************************************************************/
curl_setopt($this->curl, CURLOPT_HEADER, 1);
curl_setopt($this->curl, CURLOPT_HTTPPROXYTUNNEL, 1);
curl_setopt($this->curl, CURLOPT_PROXY, '201.80.157.12:6588');
/**************************************************************************/
}

function clean($contents)
{
return $contents = str_replace('<script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=ABQIAAAAA6ElvpTmZs4PUpZpSAoK6BSHXJsp5oogWH5jZodYSc2VMsh-GBSvecccQD_seEoYLmo-SsWfitQQEw" type="text/javascript"></script>', '', $contents);
}

function get($url)
{
$this->curl = curl_init($url);
$this->setup();

return $this->clean($this->request());
}

function getAll($reg,$str)
{
preg_match_all($reg,$str,$matches);
return $matches[1];
}

function postForm($url, $fields, $referer='')
{
$this->curl = curl_init($url);
$this->setup();
curl_setopt($this->curl, CURLOPT_URL, $url);
curl_setopt($this->curl, CURLOPT_POST, 1);
curl_setopt($this->curl, CURLOPT_REFERER, $referer);
curl_setopt($this->curl, CURLOPT_POSTFIELDS, $fields);
return $this->request();
}

function getInfo($info)
{
$info = ($info == 'lasturl') ? curl_getinfo($this->curl, CURLINFO_EFFECTIVE_URL) : curl_getinfo($this->curl, $info);
return $info;
}

function request()
{
return curl_exec($this->curl);
}
}
$curl = new Curl;

echo $curl->get('http://whatismyip.com/');

rodney88
Jul 5th 2007, 2:53 am
function setProxy($toUse) {
curl_setopt($this->curl, CURLOPT_PROXY, 'http://'.$toUse.'/');
curl_setopt($this->curl, CURLPROXY_HTTP, 'http://'.$toUse.'/');
curl_setopt($this->curl, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
}
... worked for me.

chatmasta
Jul 5th 2007, 8:21 am
Yeah after an hour or two yesterday, I realized the problem. I think my server only lets me connect to port 80 or something. It's strange, I need to talk to hostgator about it.

Thanks