Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- * Author : Denis Szalkowski Copyright © 2012
- * Licence : GNU General Public Licence v3.0
- * https://www.php.net/manual/fr/book.curl.php
- * https://php.net/manual/fr/function.curl-setopt.php
- */
- class Curl
- {
- protected $ch;
- function __construct($url,$tor=false)
- {
- $this->ch = curl_init();
- $headers= [
- 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8',
- 'Accept-Language: en-US;q=0.7,en;q=0.3'
- ];
- $options=[
- CURLOPT_HEADEROPT => CURLHEADER_UNIFIED,
- CURLOPT_HTTPHEADER => $headers,
- CURLOPT_HEADER => false,
- CURLOPT_URL => $url,
- CURLOPT_ENCODING => 'gzip,deflate',
- CURLOPT_AUTOREFERER => true,
- CURLOPT_USERAGENT => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:107.0) Gecko/20100101 Firefox/107.0',
- CURLOPT_RETURNTRANSFER => true,
- CURLOPT_COOKIESESSION => true,
- CURLOPT_FOLLOWLOCATION => true,
- CURLOPT_PROTOCOLS => CURLPROTO_HTTPS,
- CURLOPT_SSL_VERIFYPEER => false,
- CURLOPT_PROXY_SSL_VERIFYPEER => false,
- CURLOPT_SSL_VERIFYSTATUS => false,
- CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_2TLS,
- CURLOPT_CONNECTTIMEOUT => 15,
- CURLOPT_TIMEOUT => 15,
- CURLOPT_HTTPGET => true
- , CURLOPT_HTTP_CONTENT_DECODING => true,
- CURLOPT_TCP_FASTOPEN => true,
- CURLOPT_VERBOSE => false
- ];
- curl_setopt_array($this->ch,$options);
- /*
- * Tor enabled if $tor is true.
- */
- if($tor)
- {
- curl_setopt($this->ch,CURLOPT_PROXY,'127.0.0.1:9050');
- curl_setopt($this->ch,CURLOPT_PROXYTYPE,CURLPROXY_SOCKS5);
- }
- }
- /*
- * Get url content
- */
- public function get_content()
- {
- $response=false;
- $response=curl_exec($this->ch);
- $httpcode = curl_getinfo($this->ch, CURLINFO_HTTP_CODE);
- if($httpcode >= 400 and $httpcode < 200)
- {
- $response=$httpcode;
- }
- return $response;
- }
- /*
- * Destructor invoked by unset
- */
- function __destruct()
- {
- curl_close($this->ch);
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement