|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Curl; |
| 4 | + |
| 5 | +class BrowserClient extends Client |
| 6 | +{ |
| 7 | + protected $headers = array( |
| 8 | + 'Accept' => 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', |
| 9 | + 'Accept-Encoding' => 'identity', |
| 10 | + 'Accept-Language' => 'en-US,en;q=0.5', |
| 11 | + 'User-Agent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:71.0) Gecko/20100101 Firefox/71.0' |
| 12 | + ); |
| 13 | + |
| 14 | + protected $options = array( |
| 15 | + CURLOPT_ENCODING => '', // apparently curl will decode gzip automatically when this is empty |
| 16 | + CURLOPT_SSL_VERIFYHOST => 0, |
| 17 | + CURLOPT_SSL_VERIFYPEER => 0, |
| 18 | + CURLOPT_CONNECTTIMEOUT => 10, |
| 19 | + CURLOPT_TIMEOUT => 15 |
| 20 | + ); |
| 21 | + |
| 22 | + protected $cookie_file; |
| 23 | + |
| 24 | + public function __construct() |
| 25 | + { |
| 26 | + parent::__construct(); |
| 27 | + |
| 28 | + $cookie_file = join(DIRECTORY_SEPARATOR, [sys_get_temp_dir(), "BrowserClient"]); |
| 29 | + $this->setCookieFile($cookie_file); |
| 30 | + } |
| 31 | + |
| 32 | + public function setCookieFile($cookie_file) |
| 33 | + { |
| 34 | + $this->cookie_file = $cookie_file; |
| 35 | + |
| 36 | + // read & write cookies |
| 37 | + $this->options[CURLOPT_COOKIEJAR] = $cookie_file; |
| 38 | + $this->options[CURLOPT_COOKIEFILE] = $cookie_file; |
| 39 | + } |
| 40 | + |
| 41 | + public function getCookieFile() |
| 42 | + { |
| 43 | + return $this->cookie_file; |
| 44 | + } |
| 45 | + |
| 46 | + public function clearCookies() |
| 47 | + { |
| 48 | + unlink($this->getCookieFile()); |
| 49 | + } |
| 50 | +} |
0 commit comments