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&v=2&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/');
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&v=2&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/');