5
The doubt is as follows, in the network
browser console says cookies do not expire, see the image below:
But when picking up (making a request of these) these cookies with curl
expire:
ct0=e3197b1390ba24c4ae827fc6740344fa; Expires=Mon, 23 Oct 2017 14:21:33 UTC; Path=/; Domain=.twitter.com; Secure
Today the 14:21:33
they no longer work. How am I picking up these cookies?
Thus:
$obj = new stdClass;
$obj->cookies = '';
$obj->location = '';
$request = curl_init();
curl_setopt_array($request, [
CURLOPT_URL => 'https://twitter.com/',
CURLOPT_CUSTOMREQUEST => 'GET',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYHOST => false,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_HEADER => true,
CURLOPT_COOKIEJAR => getcwd() . '/cookies/' . $username . '.txt',
CURLOPT_HEADERFUNCTION => function($curl, $header) use (&$obj) {
if (stripos($header, 'Set-Cookie:') === 0) {
if (preg_match('/^Set-Cookie: \s*([^=]*)=([^;]*)/mi', $header, $matches)) {
$obj->cookies .= $matches[1] . '=' . $matches[2] . '; ';
$obj->{$matches[1]} = $matches[2];
}
}
var_dump($header);
return strlen($header);
}
]
);
$response = curl_exec($request);
Whereas:
if (stripos($header, 'Set-Cookie:') === 0) {
if (preg_match('/^Set-Cookie: \s*([^=]*)=([^;]*)/mi', $header, $matches)) {
$obj->cookies .= $matches[1] . '=' . $matches[2] . '; ';
$obj->{$matches[1]} = $matches[2];
}
}
Already plan the work so they do not expire correct?
EDITED
In the documentation I translated and says the following:
Curl has a built-in cookie analysis engine that comes into use if you want to reconnect to a server and use cookies which were stored on a previous connection (or manually manually to trick the server into believing that you had a previous connection ). To use cookies previously stored, you executes Curl as:
Curl --cookie stored_cookies_in_file http://www.example.com
And here’s what I want:
if you want to reconnect to a server and use cookies that were stored in a previous connection
Ta how I do it in PHP ?
"Curl has a cookie analysis engine, "only the
CURLOPT_COOKIEJAR
,CURLOPT_COOKIEFILE
,CURLOPT_COOKIELIST
and theCURLOPT_COOKIESESSION
use the cookie manager of Curl, the function above does not use, this has been said several times including. The code mentioned above completely ignores the expiration time, it only gets the name and value. Even, part of the questions may be answered here.– Inkeliz
@Inkeliz, that’s correct, but what I don’t understand is why Instagram cookies I can use for several months, and Twitter can’t use after hours.
– user94336
The equivalent
ct0
of Instagram is thecsrftoken
, he doesn’t care about the value, as long as thecsrftoken
is the same header valuex-csrftoken
, if both are1
will be valid, for example. Twitter may have another mechanism, updating the value periodically, including associated with session.– Inkeliz
Yes @Inkeliz, I’ve monitored twitter there, expires in a few hours, while instagram expires in 2018
– user94336