Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class easyCurl {
- private $handle;
- function start($file=null)
- {
- $this->handle=curl_init('');
- curl_setopt($this->handle, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($this->handle, CURLOPT_FOLLOWLOCATION, 1);
- curl_setopt($this->handle, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.6) Gecko/20100625 Firefox/3.6.6 (.NET CLR 3.5.30729)");
- if($file!=null)
- {
- curl_setopt($this->handle, CURLOPT_COOKIEFILE, $file);
- curl_setopt($this->handle, CURLOPT_COOKIEJAR, $file);
- }
- return $this->handle;
- }
- function prepareUserAnget($text) {
- curl_setopt($this->handle, CURLOPT_USERAGENT, $text);
- }
- function headersPrepare($headers=true) {
- if($headers==false) {
- curl_setopt($this->handle, CURLOPT_HEADER, 0);
- } else {
- curl_setopt($this->handle, CURLOPT_HEADER, 1);
- }
- }
- function prepareTimeOut($value=0) {
- if($value<=0) {
- curl_setopt($this->handle, CURLOPT_TIMEOUT, round($value,0));
- curl_setopt($this->handle, CURLOPT_CONNECTTIMEOUT, round($value,0));
- } else {
- }
- }
- function noExpect() {
- curl_setopt($this->handle, CURLOPT_HTTPHEADER, array('Expect:'));
- }
- function prepareHttpProxy($ok=false,$ip=null,$port=8080) {
- if($ok==true) {
- if($ip==null) {
- curl_setopt($this->handle, CURLOPT_HTTPPROXYTUNNEL, 0 );
- return false;
- }
- curl_setopt($this->handle, CURLOPT_HTTPPROXYTUNNEL, 1 );
- curl_setopt($this->handle, CURLOPT_PROXYTYPE, CURLPROXY_HTTP );
- curl_setopt($this->handle, CURLOPT_PROXYPORT, $port );
- curl_setopt($this->handle, CURLOPT_PROXY, $ip );
- return true;
- } else {
- curl_setopt($this->handle, CURLOPT_HTTPPROXYTUNNEL, 0 );
- return false;
- }
- }
- function prepareHttpAuth($mode='CURLAUTH_ANY',$user,$pass) {
- curl_setopt($this->handle, CURLOPT_HTTPAUTH, $mode);
- curl_setopt($this->handle, CURLOPT_USERPWD, $user.':'.$pass);
- }
- function curlPrepare($url,$get_array=false,$post_array=false)
- {
- if(isset($url)&&strlen($url)>0)
- {
- curl_setopt($this->handle, CURLOPT_URL, $url);
- }
- if(isset($get_array) && $get_array!=false)
- {
- curl_setopt($this->handle,CURLOPT_GET,1);
- if(is_array($get_array))
- {
- $getarray='';
- foreach($get_array as $key=>$value)
- {
- $getarray=$getarray.urlencode($key).'='.urlencode($value).'&';
- }
- curl_setopt($this->handle, CURLOPT_GETFIELDS, $getarray);
- }
- } else {
- /*errdbg*/ // curl_setopt($this->handle, CURLOPT_GETFIELDS, '');
- /*errdbg*/ // curl_setopt($this->handle, CURLOPT_GET, 0);
- }
- if(isset($post_array) && $post_array!=false)
- {
- curl_setopt($this->handle,CURLOPT_POST,1);
- if(is_array($post_array))
- {
- $postarray='';
- foreach($post_array as $key=>$value)
- {
- $postarray=$postarray.urlencode($key).'='.urlencode($value).'&';
- }
- curl_setopt($this->handle, CURLOPT_POSTFIELDS, $postarray);
- }
- } else {
- curl_setopt($this->handle, CURLOPT_POSTFIELDS, '');
- curl_setopt($this->handle, CURLOPT_POST, 0);
- }
- return $this->handle;
- }
- function grab()
- {
- return curl_exec($this->handle);
- }
- function getError() {
- return curl_error($this->handle);
- }
- function getErrno() {
- return curl_errno($this->handle);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement