-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy patheasyCurl.php
156 lines (129 loc) · 2.97 KB
/
easyCurl.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
<?php
/**
* @author Savaş Can Altun <[email protected]>
* @link http://savascanaltun.com.tr
* @link http://github.com/saltun
* @since 27.08.2014
* @version 1.5
*/
cLass easyCurl{
/**
* @var string
*/
public $referer="http://google.com";
/**
* @var bool|boolean
*/
public $followlocation=false;
/**
* @var bool|boolean
*/
public $header=false;
/**
* @var int
*/
public $timeout=5;
/**
* @var bool|boolean
*/
public $ssl_verifypeer=false;
/**
* @var bool|boolean
*/
public $ssl_verifyhost=false;
/**
* @var bool|boolean
*/
public $cookie=false;
/**
* @var string
*/
public $error;
/**
* @var int
*/
public $errorNumber;
/**
* @var bool|boolean
*/
public $speed="None";
/**
* @var string
*/
private $curl;
/**
* Run Class and check curl extension.
*/
public function __construct(){
if (!extension_loaded('curl')) {
die('CURL extension not found!');
}
}
/**
* CURL Base
* @param string
* @param string
* @return null
*/
public function init($url,$proxy){
$this->curl = curl_init();
curl_setopt($this->curl, CURLOPT_URL, $url);
curl_setopt($this->curl, CURLOPT_USERAGENT, getenv('USER_AGENT'));
curl_setopt($this->curl, CURLOPT_TIMEOUT, $this->timeout);
curl_setopt($this->curl, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($this->curl, CURLOPT_FOLLOWLOCATION, $this->followlocation);
curl_setopt($this->curl, CURLOPT_REFERER, $this->referer);
if ($proxy){
$proxy = explode(':', $proxy);
curl_setopt($this->curl, CURLOPT_PROXY, $proxy[0]);
curl_setopt($this->curl, CURLOPT_PROXYPORT, $proxy[1] );
}
curl_setopt($this->curl, CURLOPT_BINARYTRANSFER, TRUE);
curl_setopt($this->curl, CURLOPT_HEADER, $this->header);
$info=curl_getinfo($this->curl);
$this->speed=$info['speed_download'];
$this->errorNumber=curl_errno($this->curl);
$this->error=curl_error($this->curl);
}
/**
* Get Page source code
* @param string
* @param null|string
* @return string
*/
public function sourceCode($url,$proxy=NULL){
$this->init($url, $proxy);
$exec = curl_exec($this->curl);
return $exec;
}
/**
* Curl page post
* @param null|string
* @param null|string
* @param null|string
* @return string
*
*/
public function curlPost($url=NULL,$content=NULL,$proxy=NULL){
/**
* Check $url varible
*/
if (empty($url)) {
return "Hata : action Adresi boş";
} else if(empty($content)) {
return "Hata : Post verileri yok";
}
$this->init($url, $proxy);
curl_setopt($this->curl, CURLOPT_POST, true);
curl_setopt($this->curl, CURLOPT_POSTFIELDS, http_build_query($content));
$exec = curl_exec($this->curl);
return $exec;
}
/**
* End Class and Curl close
*/
public function __destruct(){
curl_close($this->curl);
}
}
?>