[TwitterBridge] Get cookies before sending request (#1232)

* [TwitterBridge] Get cookies before sending request

Twitter now requires cookies to be set before requesting a page. This will fetch the cookies and send them to `getSimpleHTMLDOM()`.

* Formatting fixes
This commit is contained in:
triatic 2019-07-26 09:36:59 +01:00 committed by Teromene
parent eb942bc498
commit 2bb9480555

View file

@ -170,8 +170,10 @@ EOD
public function collectData(){
$html = '';
$page = $this->getURI();
$cookies = $this->getCookies($page);
$html = getSimpleHTMLDOM($this->getURI());
$html = getSimpleHTMLDOM($page, array("Cookie: $cookies"));
if(!$html) {
switch($this->queriedContext) {
case 'By keyword or hashtag':
@ -428,4 +430,27 @@ EOD;
return null;
}
private function getCookies($pageURL){
$ctx = stream_context_create(array(
'http' => array(
'follow_location' => false
)
)
);
$a = file_get_contents($pageURL, 0, $ctx);
//First request to get the cookie
$cookies = '';
foreach($http_response_header as $hdr) {
if(stripos($hdr, 'Set-Cookie') !== false) {
$cLine = explode(':', $hdr)[1];
$cLine = explode(';', $cLine)[0];
$cookies .= ';' . $cLine;
}
}
return substr($cookies, 2);
}
}