| @@ 92-132 (lines=41) @@ | ||
| 89 | * @return string data |
|
| 90 | * @access public |
|
| 91 | */ |
|
| 92 | function sendPostData($url, $postdata, $ip=null, $timeout=10) |
|
| 93 | { |
|
| 94 | //set various curl options first |
|
| 95 | // set url to post to |
|
| 96 | curl_setopt($this->ch, CURLOPT_URL,$url); |
|
| 97 | // return into a variable rather than displaying it |
|
| 98 | curl_setopt($this->ch, CURLOPT_RETURNTRANSFER,true); |
|
| 99 | ||
| 100 | //bind to specific ip address if it is sent trough arguments |
|
| 101 | if($ip) { |
|
| 102 | if($this->debug) |
|
| 103 | { |
|
| 104 | echo "Binding to ip $ip\n"; |
|
| 105 | } |
|
| 106 | curl_setopt($this->ch,CURLOPT_INTERFACE,$ip); |
|
| 107 | } |
|
| 108 | ||
| 109 | //set curl function timeout to $timeout |
|
| 110 | curl_setopt($this->ch, CURLOPT_TIMEOUT, $timeout); |
|
| 111 | ||
| 112 | //set method to post |
|
| 113 | curl_setopt($this->ch, CURLOPT_POST, true); |
|
| 114 | // set post string |
|
| 115 | curl_setopt($this->ch, CURLOPT_POSTFIELDS, $postdata); |
|
| 116 | ||
| 117 | //and finally send curl request |
|
| 118 | $result = curl_exec_redir($this->ch); |
|
| 119 | if(curl_errno($this->ch)) { |
|
| 120 | if($this->debug) { |
|
| 121 | echo "Error Occured in Curl\n"; |
|
| 122 | echo "Error number: " .curl_errno($this->ch) ."\n"; |
|
| 123 | echo "Error message: " .curl_error($this->ch)."\n"; |
|
| 124 | } |
|
| 125 | return false; |
|
| 126 | } else { |
|
| 127 | return $result; |
|
| 128 | } |
|
| 129 | } |
|
| 130 | ||
| 131 | /** |
|
| 132 | * fetch data from target URL |
|
| 133 | * return data returned from url or false if error occured |
|
| 134 | * @param string url |
|
| 135 | * @param string ip address to bind (default null) |
|
| @@ 140-176 (lines=37) @@ | ||
| 137 | * @return string data |
|
| 138 | * @access public |
|
| 139 | */ |
|
| 140 | function fetchUrl($url, $ip=null, $timeout=5) |
|
| 141 | { |
|
| 142 | // set url to post to |
|
| 143 | curl_setopt($this->ch, CURLOPT_URL,$url); |
|
| 144 | ||
| 145 | //set method to get |
|
| 146 | curl_setopt($this->ch, CURLOPT_HTTPGET,true); |
|
| 147 | // return into a variable rather than displaying it |
|
| 148 | curl_setopt($this->ch, CURLOPT_RETURNTRANSFER,true); |
|
| 149 | ||
| 150 | //bind to specific ip address if it is sent trough arguments |
|
| 151 | if($ip) { |
|
| 152 | if($this->debug) { |
|
| 153 | echo "Binding to ip $ip\n"; |
|
| 154 | } |
|
| 155 | ||
| 156 | curl_setopt($this->ch,CURLOPT_INTERFACE,$ip); |
|
| 157 | } |
|
| 158 | ||
| 159 | //set curl function timeout to $timeout |
|
| 160 | curl_setopt($this->ch, CURLOPT_TIMEOUT, $timeout); |
|
| 161 | ||
| 162 | //and finally send curl request |
|
| 163 | $result = curl_exec_redir($this->ch); |
|
| 164 | if(curl_errno($this->ch)) { |
|
| 165 | if($this->debug) { |
|
| 166 | echo "Error Occured in Curl\n"; |
|
| 167 | echo "Error number: " .curl_errno($this->ch) ."\n"; |
|
| 168 | echo "Error message: " .curl_error($this->ch)."\n"; |
|
| 169 | } |
|
| 170 | return false; |
|
| 171 | } else { |
|
| 172 | return $result; |
|
| 173 | } |
|
| 174 | } |
|
| 175 | ||
| 176 | /** |
|
| 177 | * Fetch data from target URL |
|
| 178 | * and store it directly to file |
|
| 179 | * @param string url |
|
| @@ 186-221 (lines=36) @@ | ||
| 183 | * @return boolean true on success false othervise |
|
| 184 | * @access public |
|
| 185 | */ |
|
| 186 | function fetchIntoFile($url, $fp, $ip=null, $timeout=5) |
|
| 187 | { |
|
| 188 | // set url to post to |
|
| 189 | curl_setopt($this->ch, CURLOPT_URL,$url); |
|
| 190 | //set method to get |
|
| 191 | curl_setopt($this->ch, CURLOPT_HTTPGET, true); |
|
| 192 | // store data into file rather than displaying it |
|
| 193 | curl_setopt($this->ch, CURLOPT_FILE, $fp); |
|
| 194 | ||
| 195 | //bind to specific ip address if it is sent trough arguments |
|
| 196 | if($ip) { |
|
| 197 | if($this->debug) { |
|
| 198 | echo "Binding to ip $ip\n"; |
|
| 199 | } |
|
| 200 | curl_setopt($this->ch, CURLOPT_INTERFACE, $ip); |
|
| 201 | } |
|
| 202 | ||
| 203 | //set curl function timeout to $timeout |
|
| 204 | curl_setopt($this->ch, CURLOPT_TIMEOUT, $timeout); |
|
| 205 | ||
| 206 | //and finally send curl request |
|
| 207 | $result = curl_exec_redir($this->ch); |
|
| 208 | if(curl_errno($this->ch)) { |
|
| 209 | if($this->debug) { |
|
| 210 | echo "Error Occured in Curl\n"; |
|
| 211 | echo "Error number: " .curl_errno($this->ch) ."\n"; |
|
| 212 | echo "Error message: " .curl_error($this->ch)."\n"; |
|
| 213 | } |
|
| 214 | ||
| 215 | return false; |
|
| 216 | } else { |
|
| 217 | return true; |
|
| 218 | } |
|
| 219 | } |
|
| 220 | ||
| 221 | /** |
|
| 222 | * Send multipart post data to the target URL |
|
| 223 | * return data returned from url or false if error occured |
|
| 224 | * (contribution by vule nikolic, [email protected]) |
|