Skip to content

Commit 33ab9f9

Browse files
committed
updated BrowserClient
1 parent 719bdfd commit 33ab9f9

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

src/BrowserClient.php

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44

55
class BrowserClient extends Client
66
{
7+
// HTTP headers that uniquely identify this browser such as User-Agent
78
protected $headers = array(
89
'Accept' => 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
9-
'Accept-Encoding' => 'identity',
10+
'Accept-Encoding' => 'gzip, deflate',
1011
'Accept-Language' => 'en-US,en;q=0.5',
1112
'User-Agent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:71.0) Gecko/20100101 Firefox/71.0'
1213
);
@@ -15,10 +16,12 @@ class BrowserClient extends Client
1516
CURLOPT_ENCODING => '', // apparently curl will decode gzip automatically when this is empty
1617
CURLOPT_SSL_VERIFYHOST => 0,
1718
CURLOPT_SSL_VERIFYPEER => 0,
19+
CURLOPT_AUTOREFERER => 1,
1820
CURLOPT_CONNECTTIMEOUT => 10,
1921
CURLOPT_TIMEOUT => 15
2022
);
2123

24+
/** @var string Where the cookies are stored */
2225
protected $cookie_file;
2326

2427
public function __construct()
@@ -29,6 +32,20 @@ public function __construct()
2932
$this->setCookieFile($cookie_file);
3033
}
3134

35+
/**
36+
* Format ip:port or null to use direct connection
37+
* @param $proxy_server
38+
*/
39+
public function setProxy($proxy_server)
40+
{
41+
$this->options[CURLOPT_PROXY] = $proxy_server;
42+
}
43+
44+
public function getProxy()
45+
{
46+
return !empty($this->options[CURLOPT_PROXY]) ? $this->options[CURLOPT_PROXY] : null;
47+
}
48+
3249
public function setCookieFile($cookie_file)
3350
{
3451
$this->cookie_file = $cookie_file;
@@ -43,6 +60,18 @@ public function getCookieFile()
4360
return $this->cookie_file;
4461
}
4562

63+
// Manual alternative for: curl_getinfo($ch, CURLINFO_COOKIELIST));
64+
public function getCookies()
65+
{
66+
$contents = @file_get_contents($this->getCookieFile());
67+
return $contents;
68+
}
69+
70+
public function setCookies($cookies)
71+
{
72+
return @file_put_contents($this->getCookieFile(), $cookies) !== false;
73+
}
74+
4675
public function clearCookies()
4776
{
4877
unlink($this->getCookieFile());

0 commit comments

Comments
 (0)