path_to_cookies=$cookies;
if($browser!="")
$this->_useragent=$browser;
if($referrer!="")
$this->_referer=$referrer;
$this->headers[] = "Accept: */*";
$this->headers[] = "Cache-Control: no-cache, must-revalidate";
$this->headers[] = "Cache-Control: max-age=0";
$this->headers[] = "Connection: keep-alive";
$this->headers[] = "Accept-Charset: utf-8";
$this->headers[] = "Accept-Language: en";
$this->init_curl();
}
public function init_curl()
{
//$fp=fopen($this->_debugFileLocation,"w");
$this->s = curl_init();
curl_setopt($this->s, CURLOPT_HTTPHEADER, $this->headers);
curl_setopt($this->s,CURLOPT_URL,$this->_url);
curl_setopt($this->s, CURLOPT_CONNECTTIMEOUT, 100);
curl_setopt($this->s,CURLOPT_TIMEOUT,$this->_timeout);
curl_setopt($this->s,CURLOPT_MAXREDIRS,$this->_maxRedirects);
curl_setopt($this->s, CURLOPT_RETURNTRANSFER, true);
curl_setopt($this->s, CURLOPT_FRESH_CONNECT, true);
curl_setopt($this->s, CURLOPT_COOKIESESSION, true);
curl_setopt($this->s, CURLOPT_FOLLOWLOCATION, true);
// curl_setopt($this->s, CURLOPT_AUTOREFERER, true);
//curl_setopt($this->s, CURLOPT_FAILONERROR, false);
curl_setopt($this->s, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($this->s, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($this->s, CURLOPT_HEADER, true); // Display headers
curl_setopt($this->s, CURLOPT_VERBOSE, true); // Display communication with server
curl_setopt($this->s,CURLOPT_USERAGENT,$this->_useragent);
curl_setopt($this->s,CURLOPT_REFERER,$this->_referer);
$this->setCookiFileLocation();
if($this->authentication == 1){
curl_setopt($this->s, CURLOPT_USERPWD, $this->auth_name.':'.$this->auth_pass);
}
}
public function createCurl($url = 'nul')
{
try
{
$result=$this->exec__();
if ($result['curl_error']) throw new Exception($result['curl_error']);
if (($result['http_code']!='') &&($result['http_code']!='0') &&($result['http_code']!='200') && ($result['http_code']!='500') && ($result['http_code']!='302') && ($result['http_code']!='400') && ($result['http_code']!='403')) throw new Exception("HTTP Code = ".$result['http_code']);
// if (!$result['body']) throw new Exception("Body of file is empty");
}
catch (Exception $e)
{
$result['curl_error']="Curl Error: ".$e->getMessage()."
".$this->_url."
";
}
curl_setopt($this->s,CURLOPT_POST,false);
return $result;
}
public function exec__()
{
$response = curl_exec($this->s);
$error = curl_error($this->s);
$result = array( 'header' => '',
'body' => '',
'curl_error' => '',
'http_code' => '',
'last_url' => '');
if ( $error != "" )
{
$result['curl_error'] = $error;
}
$header_size = curl_getinfo($this->s,CURLINFO_HEADER_SIZE);
$result['header'] = substr($response, 0, $header_size);
$result['body'] = substr( $response, $header_size );
$result['http_code'] = curl_getinfo($this->s,CURLINFO_HTTP_CODE);
$result['last_url'] = curl_getinfo($this->s,CURLINFO_EFFECTIVE_URL);
if($this->debug==1)
{
echo "
----------------------------Curl Results -----------------------
";
echo "Curl header:".$result['header']."
";
echo "Curl http_code:".$result['http_code']."
";
echo "Curl last_url:".$result['last_url']."
";
echo "
Curl body:";
display_html_content($result['body']);
}
return $result;
}
public function close()
{
curl_close($this->s);
}
public function useAuth($use){
$this->authentication = 0;
if($use == true) $this->authentication = 1;
}
public function set_proxy($proxy="")
{
if($proxy!="")
$this->proxy=$proxy;
if($this->proxy!="")
{
//curl_setopt($this->s, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
if($this->HTTPPROXYTUNNEL==1)
curl_setopt($this->s, CURLOPT_HTTPPROXYTUNNEL, $this->HTTPPROXYTUNNEL);
curl_setopt($this->s, CURLOPT_PROXY, $this->proxy);
if($this->debug>=1)
echo "proxy: ". $this->proxy."
";
}
else
curl_setopt($this->s, CURLOPT_HTTPPROXYTUNNEL, 0);
}
public function setTimeOut($time){
curl_setopt($this->s, CURLOPT_CONNECTTIMEOUT, $time);
curl_setopt($this->s,CURLOPT_TIMEOUT,$time * 3);
}
public function setReferer($referer){
curl_setopt($this->s,CURLOPT_REFERER,$referer);
$this->_referer=$referer;
}
public function setCookiFileLocation($path="")
{
if($path!="")
$this->path_to_cookies=$path;
if($this->path_to_cookies!="")
{
/*curl_setopt($this->s, CURLOPT_FRESH_CONNECT, 1);
curl_setopt($this->s, CURLOPT_COOKIESESSION, 1);*/
curl_setopt($this->s, CURLOPT_COOKIEJAR, $this->path_to_cookies);
curl_setopt($this->s, CURLOPT_COOKIEFILE, $this->path_to_cookies);
//curl_setopt($this->s, CURLOPT_COOKIE, file_get_contents($this->path_to_cookies));
}
}
public function setUrl($url)
{
curl_setopt($this->s,CURLOPT_URL,$url);
$this->_url=$url;
}
public function setPost ($postFields)
{
if($postFields=="")
{
curl_setopt($this->s,CURLOPT_POST,false);
}
else
{
/*$tabl=split("&",$postFields);
foreach($tabl as $one)
{
$tab2=split("=",$one);
$id=$tab2[0];
$listFields[$id]=$tab2[1];
}*/
curl_setopt($this->s,CURLOPT_POST,1);
curl_setopt($this->s,CURLOPT_POSTFIELDS,$postFields);
}
}
public function setUserAgent($userAgent)
{
curl_setopt($this->s,CURLOPT_USERAGENT,$userAgent);
}
public function getHttpStatus()
{
return $this->_status;
}
public function __tostring(){
return $this->_webpage;
}
}