├── LICENSE ├── example ├── index.php └── easyCurl.php ├── easyCurl.php └── README.md /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2014 Savaş Can ALTUN 2 | -------------------------------------------------------------------------------- /example/index.php: -------------------------------------------------------------------------------- 1 | referer="http://savascanaltun.com.tr"; 8 | 9 | /* eğer ki adres yönlendiriliyor ise takip edilsin mi ? */ 10 | $easyCurl->followlocation=false; 11 | 12 | /* header bilgisi gönderilsin mi ? */ 13 | $easyCurl->header=false; 14 | 15 | /* maximum bekleme süresi ? */ 16 | $easyCurl->timeout=5; 17 | 18 | /* ssl ? */ 19 | $easyCurl->ssl_verifypeer=false; 20 | $easyCurl->ssl_verifyhost=false; 21 | 22 | /* çerezler aktif mi ? */ 23 | 24 | $easyCurl->cookie=false; 25 | 26 | 27 | /* 28 | * Sayfa Kaynak kodlarını alma 29 | * sourceCode Fonksiyonuna adresi tanımlayarak kaynak kodlarını alıp değişkene aktara bilirsiniz veya ekrana yansıta bilirsiniz. 30 | * Referans adresi vs.. düzenlemek için bu fonksiyondan önce referer gibi değişkenlere değer vermelisiniz. 31 | * Proxy kullanmak için 2. bir parametrede proxy adresini belirtmeniz yeterlidir. proxyip:sifre şeklinde göndermelisiniz 32 | */ 33 | 34 | $source=$easyCurl->sourceCode('http://savascanaltun.com.tr'); 35 | echo $source; 36 | 37 | 38 | 39 | /* 40 | * CURL POST İşlemi 41 | * post yapılacak formdaki action alanındaki adres 42 | * ikinci parametrede ise bir dizi gönderip bu diziyi form name ve değerlerine göre göndertiniz. 43 | * Proxy kullanmak için 3. bir parametrede proxy adresini belirtmeniz yeterlidir. proxyip:sifre şeklinde göndermelisiniz 44 | */ 45 | 46 | $postData=array( 47 | 'baslik'=>'easyCurl Class test', 48 | 'mesaj'=>'Merhaba ben savaş can altun bu bizim ilk testimiz.' 49 | ); 50 | 51 | $post=$easyCurl->curlPost('http://savascanaltun.com.tr/app/php/test/post.php',$postData); 52 | 53 | echo $post; 54 | 55 | /* 56 | * Hatalara Ulaşmak 57 | * -> Hata Sayısına ulaşmak $class->errorNumber 58 | * -> Hataya ulaşmak $class->error 59 | */ 60 | echo "Error Number : ".$easyCurl->errorNumber; 61 | echo "Error : ".$easyCurl->error; 62 | 63 | /* 64 | * CURL işleminin download hızını alma. 65 | * $class->speed 66 | */ 67 | echo "
"; 68 | echo "Speed : ".$easyCurl->speed; 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | ?> -------------------------------------------------------------------------------- /easyCurl.php: -------------------------------------------------------------------------------- 1 | 4 | * @link http://savascanaltun.com.tr 5 | * @link http://github.com/saltun 6 | * @since 27.08.2014 7 | * @version 1.5 8 | */ 9 | 10 | cLass easyCurl{ 11 | 12 | /** 13 | * @var string 14 | */ 15 | public $referer="http://google.com"; 16 | 17 | /** 18 | * @var bool|boolean 19 | */ 20 | public $followlocation=false; 21 | 22 | /** 23 | * @var bool|boolean 24 | */ 25 | public $header=false; 26 | 27 | /** 28 | * @var int 29 | */ 30 | public $timeout=5; 31 | 32 | /** 33 | * @var bool|boolean 34 | */ 35 | public $ssl_verifypeer=false; 36 | 37 | /** 38 | * @var bool|boolean 39 | */ 40 | public $ssl_verifyhost=false; 41 | 42 | /** 43 | * @var bool|boolean 44 | */ 45 | public $cookie=false; 46 | 47 | /** 48 | * @var string 49 | */ 50 | public $error; 51 | 52 | /** 53 | * @var int 54 | */ 55 | public $errorNumber; 56 | 57 | /** 58 | * @var bool|boolean 59 | */ 60 | public $speed="None"; 61 | 62 | /** 63 | * @var string 64 | */ 65 | private $curl; 66 | 67 | /** 68 | * Run Class and check curl extension. 69 | */ 70 | public function __construct(){ 71 | if (!extension_loaded('curl')) { 72 | die('CURL extension not found!'); 73 | } 74 | } 75 | 76 | /** 77 | * CURL Base 78 | * @param string 79 | * @param string 80 | * @return null 81 | */ 82 | public function init($url,$proxy){ 83 | $this->curl = curl_init(); 84 | curl_setopt($this->curl, CURLOPT_URL, $url); 85 | curl_setopt($this->curl, CURLOPT_USERAGENT, getenv('USER_AGENT')); 86 | curl_setopt($this->curl, CURLOPT_TIMEOUT, $this->timeout); 87 | curl_setopt($this->curl, CURLOPT_RETURNTRANSFER, TRUE); 88 | curl_setopt($this->curl, CURLOPT_FOLLOWLOCATION, $this->followlocation); 89 | curl_setopt($this->curl, CURLOPT_REFERER, $this->referer); 90 | if ($proxy){ 91 | $proxy = explode(':', $proxy); 92 | curl_setopt($this->curl, CURLOPT_PROXY, $proxy[0]); 93 | curl_setopt($this->curl, CURLOPT_PROXYPORT, $proxy[1] ); 94 | } 95 | curl_setopt($this->curl, CURLOPT_BINARYTRANSFER, TRUE); 96 | curl_setopt($this->curl, CURLOPT_HEADER, $this->header); 97 | $info=curl_getinfo($this->curl); 98 | $this->speed=$info['speed_download']; 99 | $this->errorNumber=curl_errno($this->curl); 100 | $this->error=curl_error($this->curl); 101 | 102 | 103 | 104 | } 105 | 106 | 107 | /** 108 | * Get Page source code 109 | * @param string 110 | * @param null|string 111 | * @return string 112 | */ 113 | public function sourceCode($url,$proxy=NULL){ 114 | $this->init($url, $proxy); 115 | $exec = curl_exec($this->curl); 116 | return $exec; 117 | } 118 | 119 | /** 120 | * Curl page post 121 | * @param null|string 122 | * @param null|string 123 | * @param null|string 124 | * @return string 125 | * 126 | */ 127 | 128 | public function curlPost($url=NULL,$content=NULL,$proxy=NULL){ 129 | 130 | /** 131 | * Check $url varible 132 | */ 133 | if (empty($url)) { 134 | return "Hata : action Adresi boş"; 135 | } else if(empty($content)) { 136 | return "Hata : Post verileri yok"; 137 | } 138 | 139 | $this->init($url, $proxy); 140 | curl_setopt($this->curl, CURLOPT_POST, true); 141 | curl_setopt($this->curl, CURLOPT_POSTFIELDS, http_build_query($content)); 142 | 143 | $exec = curl_exec($this->curl); 144 | return $exec; 145 | 146 | } 147 | 148 | /** 149 | * End Class and Curl close 150 | */ 151 | public function __destruct(){ 152 | curl_close($this->curl); 153 | } 154 | } 155 | 156 | ?> 157 | -------------------------------------------------------------------------------- /example/easyCurl.php: -------------------------------------------------------------------------------- 1 | 4 | * @link http://savascanaltun.com.tr 5 | * @link http://github.com/saltun 6 | * @since 27.08.2014 7 | * @version 1.5 8 | */ 9 | 10 | cLass easyCurl{ 11 | 12 | /** 13 | * @var string 14 | */ 15 | public $referer="http://google.com"; 16 | 17 | /** 18 | * @var bool|boolean 19 | */ 20 | public $followlocation=false; 21 | 22 | /** 23 | * @var bool|boolean 24 | */ 25 | public $header=false; 26 | 27 | /** 28 | * @var int 29 | */ 30 | public $timeout=5; 31 | 32 | /** 33 | * @var bool|boolean 34 | */ 35 | public $ssl_verifypeer=false; 36 | 37 | /** 38 | * @var bool|boolean 39 | */ 40 | public $ssl_verifyhost=false; 41 | 42 | /** 43 | * @var bool|boolean 44 | */ 45 | public $cookie=false; 46 | 47 | /** 48 | * @var string 49 | */ 50 | public $error; 51 | 52 | /** 53 | * @var int 54 | */ 55 | public $errorNumber; 56 | 57 | /** 58 | * @var bool|boolean 59 | */ 60 | public $speed="None"; 61 | 62 | /** 63 | * @var string 64 | */ 65 | private $curl; 66 | 67 | /** 68 | * Run Class and check curl extension. 69 | */ 70 | public function __construct(){ 71 | if (!extension_loaded('curl')) { 72 | die('CURL extension not found!'); 73 | } 74 | } 75 | 76 | /** 77 | * CURL Base 78 | * @param string 79 | * @param string 80 | * @return null 81 | */ 82 | public function init($url,$proxy){ 83 | $this->curl = curl_init(); 84 | curl_setopt($this->curl, CURLOPT_URL, $url); 85 | curl_setopt($this->curl, CURLOPT_USERAGENT, getenv('USER_AGENT')); 86 | curl_setopt($this->curl, CURLOPT_TIMEOUT, $this->timeout); 87 | curl_setopt($this->curl, CURLOPT_RETURNTRANSFER, TRUE); 88 | curl_setopt($this->curl, CURLOPT_FOLLOWLOCATION, $this->followlocation); 89 | curl_setopt($this->curl, CURLOPT_REFERER, $this->referer); 90 | if ($proxy){ 91 | $proxy = explode(':', $proxy); 92 | curl_setopt($this->curl, CURLOPT_PROXY, $proxy[0]); 93 | curl_setopt($this->curl, CURLOPT_PROXYPORT, $proxy[1] ); 94 | } 95 | curl_setopt($this->curl, CURLOPT_BINARYTRANSFER, TRUE); 96 | curl_setopt($this->curl, CURLOPT_HEADER, $this->header); 97 | $info=curl_getinfo($this->curl); 98 | $this->speed=$info['speed_download']; 99 | $this->errorNumber=curl_errno($this->curl); 100 | $this->error=curl_error($this->curl); 101 | 102 | 103 | 104 | } 105 | 106 | 107 | /** 108 | * Get Page source code 109 | * @param string 110 | * @param null|string 111 | * @return string 112 | */ 113 | public function sourceCode($url,$proxy=NULL){ 114 | $this->init($url, $proxy); 115 | $exec = curl_exec($this->curl); 116 | return $exec; 117 | } 118 | 119 | /** 120 | * Curl page post 121 | * @param null|string 122 | * @param null|string 123 | * @param null|string 124 | * @return string 125 | * 126 | */ 127 | 128 | public function curlPost($url=NULL,$content=NULL,$proxy=NULL){ 129 | 130 | /** 131 | * Check $url varible 132 | */ 133 | if (empty($url)) { 134 | return "Hata : action Adresi boş"; 135 | } else if(empty($content)) { 136 | return "Hata : Post verileri yok"; 137 | } 138 | 139 | $this->init($url, $proxy); 140 | curl_setopt($this->curl, CURLOPT_POST, true); 141 | curl_setopt($this->curl, CURLOPT_POSTFIELDS, http_build_query($content)); 142 | 143 | $exec = curl_exec($this->curl); 144 | return $exec; 145 | 146 | } 147 | 148 | /** 149 | * End Class and Curl close 150 | */ 151 | public function __destruct(){ 152 | curl_close($this->curl); 153 | } 154 | } 155 | 156 | ?> 157 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | EasyCurl Sınıfı - easyCurl Class PHP 2 | ==================== 3 | 4 | easyCurl sınıfı sayesinde basit curl işlemleriniz çok az kod bilgisi ile yapabilirsiniz. 5 | 6 | Alttaki örnek ile bir siteye proxy ile bağlanma veri çekme ve bir sitedeki veriyi post etme gibi örneklere ulaşabilirsiniz. 7 | 8 | Geliştirilmesinde sizde katkı sağlar iseniz çok memnun oluruz. 9 | 10 | 11 | Not !! 12 | --------------------- 13 | Eğer sınıf ile beraber proxy kullanmak isterseniz kullanmak istediğiniz proxy adresini belirtirken proxyadresi:port şeklinde belirtiniz. Yani proxyadresi ikinokta ( : ) ardından ise port numarası. 14 | 15 | Sınıfı dahil edip calıştıralım 16 | --------------------- 17 | ``` php 18 | require_once "easyCurl.php"; 19 | 20 | $easyCurl = new easyCurl(); 21 | ``` 22 | Bir adresten kaynak kodlarını almak 23 | --------------------- 24 | ``` php 25 | /* 26 | * Sayfa Kaynak kodlarını alma 27 | * SourceCode Fonksiyonuna adresi tanımlayarak kaynak kodlarını alıp değişkene aktarabilirsiniz veya ekrana yansıtabilirsiniz. 28 | * Referans adresi vs.. düzenlemek için bu fonksiyondan önce referer gibi değişkenlere değer vermelisiniz. 29 | * Proxy kullanmak için 2. bir parametrede proxy adresini belirtmeniz yeterlidir. proxyip:sifre şeklinde göndermelisiniz 30 | */ 31 | 32 | $source=$easyCurl->sourceCode('http://savascanaltun.com.tr'); 33 | ``` 34 | 35 | Proxy Kullanılmış örnek 36 | --------------------- 37 | ``` php 38 | $source=$easyCurl->sourceCode('http://savascanaltun.com.tr','122.323.32.22:8082'); 39 | ``` 40 | 41 | Bir adresteki formu post ettirmek 42 | --------------------- 43 | Birinci parametrede post edilecek sayfa yanı formun action kısmını veriniz 2. parametrede ise bir dizi gönderip burada name ve değerlerini belirtiniz. Alttaki örnekteki formda baslik ve mesaj alanları mevcuttu ona göre yapıldı. Eğer sizde misal username ve password alanları var ise ona göre ayarlamanız gerekmektedir. 44 | 45 | ``` php 46 | /* 47 | * CURL POST İşlemi 48 | * post yapılacak formdaki action alanındaki adres 49 | * ikinci parametrede ise bir dizi gönderip bu diziyi form name ve değerlerine göre göndertiniz. 50 | * Proxy kullanmak için 3. bir parametrede proxy adresini belirtmeniz yeterlidir. proxyip:sifre şeklinde göndermelisiniz 51 | */ 52 | 53 | $postData=array( 54 | 'baslik'=>'easyCurl Class test', 55 | 'mesaj'=>'Merhaba ben savaş can altun bu bizim ilk testimiz.' 56 | ); 57 | 58 | $post=$easyCurl->curlPost('http://savascanaltun.com.tr/app/php/test/post.php',$postData); 59 | 60 | ``` 61 | 62 | Sınıf ile kullana bileceğiniz metodlar 63 | ==================== 64 | 65 | Referans adresi belirtmek isterseniz 66 | --------------------- 67 | ``` php 68 | $easyCurl->referer="http://savascanaltun.com.tr"; 69 | ``` 70 | 71 | Adres yönleniyor ve takip etmek istiyor iseniz 72 | --------------------- 73 | ``` php 74 | $easyCurl->followlocation=true; 75 | ``` 76 | 77 | Header bilgisi gönderilsin istiyor iseniz 78 | --------------------- 79 | ``` php 80 | $easyCurl->header=true; 81 | ``` 82 | 83 | Bir bağlantının maximum bekleme süresini ayarlamak ( default : 5 ) 84 | --------------------- 85 | ``` php 86 | $easyCurl->timeout=5; 87 | ``` 88 | 89 | Pekiya ssl ? 90 | --------------------- 91 | ``` php 92 | $easyCurl->ssl_verifypeer=true; 93 | $easyCurl->ssl_verifyhost=true; 94 | 95 | ``` 96 | Çerezleri aktif etmek istiyor iseniz 97 | --------------------- 98 | ``` php 99 | $easyCurl->cookie=true; 100 | ``` 101 | 102 | Hatalara ulaşma 103 | --------------------- 104 | Hata sayısına ulaşma ; 105 | ``` php 106 | $easyCurl->errorNumber; 107 | ``` 108 | Hataya ulaşma ; 109 | ``` php 110 | $easyCurl->error; 111 | ``` 112 | 113 | 114 | Hız bilgisini edinme 115 | --------------------- 116 | ``` php 117 | $easyCurl->speed; 118 | ``` 119 | 120 | 121 | 122 | Author : [Savas Can ALTUN](http://savascanaltun.com.tr/) 123 | Mail : savascanaltun@gmail.com 124 | Web : http://savascanaltun.com.tr 125 | 126 | 127 | --------------------------------------------------------------------------------