1
OBS: THE COMPLETE CODE IS HERE, but I made this adjustment to receive the cookies
I am trying to read the cookie files to make the necessary requests to stop get the result I hope, see my code:
$tokens = ['_twitter_sess', 'ct0', 'auth_token'];
foreach (glob($this->_cookieFile) as $file) {
$pointer = fopen($file, 'r');
while (!feof($pointer)) {
$line = fgets($pointer);
foreach ($tokens as $token) {
if (stripos($line, $token) !== false) {
var_dump($line);
curl_setopt_array($request, [
CURLOPT_COOKIEFILE => $line,
CURLOPT_HTTPHEADER => [
'origin: https://twitter.com',
'authorization: Bearer ' . $bearer,
'x-csrf-token: ' . $line,
'referer: https://twitter.com/',
'x-twitter-auth-type: OAuth2Session',
'x-twitter-active-user: yes',
],
CURLOPT_POSTFIELDS => http_build_query([
'challenges_passed' => false,
'handles_challenges' => 1,
'include_blocked_by' => true,
'include_blocking' => true,
'include_can_dm' => true,
'include_followed_by' => true,
'include_mute_edge' => true,
'skip_status' => true,
'user_id' => Session::get('username'),
], '', '&', PHP_QUERY_RFC3986),
]
);
break;
}
}
}
}
But when giving a var_dump
in $line
, I receive as return:
I need to read each line in one array associativo
or read all cookies at once.
So how do I return from mine cURL
get back to me:
'{"errors":[{"code":220,"message":"Your credentials do not allow access to this resource."}]}' (length=92)
What associative array would that be?
– Woss
Example:
$line['ct0'
],$line['_twitter_sess']
... understands?– user89335
This is a format Netscape, this link has all the documentation. Also if you are picking up the cookie you do not need to use this format, you have the
CURLOPT_HEADERFUNCTION
which allows you to extract this directly from the header. Also you don’t need any associative array, at least Curl already supports the Netscape format if you use the "cookie engine" (i.eCOOKIEFILE
orCOOKIELIST
), me said it here.– Inkeliz
@Inkeliz, but if I’m saved the file, what’s the logic in not using it? The yes I saw this answer. I want to use the file, as you said in the answer,
CUROPT_COOKIE
would solve right ? but I have 7 cookies saved in the format Netscape. I need everyone.– user89335
Possible duplicate of Turning archive content into cookies
– Woss
@Andersoncarloswoss Duplicate, but where’s the answer?... I’ll erase that one and leave this one.
– user89335
Duplicate in the sense that you’re polluting the community with repeated questions because you didn’t get the answer. This is not good practice and should not be encouraged. If you have asked the question before and no one has answered, it may be interesting to review the question by observing what can improve or offer a reward.
– Woss
@Andersoncarloswoss, you’re right, forgive me, but my question is completely different now. Ta tense solve this problem.
– user89335
If it’s already on file, use the
CURLOPT_COOKIEFILE
it accepts this format normally. See the documentation, it accepts both in Netscape format and in "Set-Cookie format".– Inkeliz
@Inkeliz, but does it read all the files from the folder? I need to put in case I just need the
twitter_sess
andauth_token
, since ct0 saved in a bank.– user89335