Following the concept This happened to me, and now it does not want to work any more.
First
I enter with a normal account, without being blocked.
Second
Soon it's on my system and it blocks, I go on twitter and it sends me to twitter.com/account/access
In case of this system it was to show the link in var_dump($header);
also, and thus to play in switch
as @Inkeliz mentioned in the answer.
But none of this worked, just Incorrect user and / or password works, and correct username and password important to warn the user that the account has been blocked does not work, here is the whole code:
<?php
$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_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];
}
}
return strlen($header);
}
]
);
$response = curl_exec($request);
if (preg_match('/value="(.*?)" name="authenticity_token"/', $response, $matches)) {
$authenticity_token = $matches[1];
}
$post = http_build_query([
'session' => [
'username_or_email' => 'teste1',
'password' => 'teste0'
],
'return_to_ssl' => true,
'scribe_log' => '',
'redirect_after_login' => '/',
'authenticity_token' => $authenticity_token
]
);
curl_setopt_array($request, [
CURLOPT_URL => 'https://twitter.com/sessions',
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => $post,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYHOST => false,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_FOLLOWLOCATION => false,
CURLOPT_HEADER => true,
CURLOPT_HTTPHEADER => [
'content-type:application/x-www-form-urlencoded',
'origin:https://twitter.com',
'referer:https://twitter.com/login',
'upgrade-insecure-requests:1',
'user-agent:Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36',
],
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];
}
}
if (stripos($header, 'Location:') === 0) {
$obj->location = trim(str_ireplace('Location:', '', trim($header)));
}
return strlen($header);
},
CURLOPT_COOKIE => $obj->cookies,
]
);
$response = curl_exec($request);
curl_close($request);
$obj->location = trim(explode('?', $obj->location)[0], '/');
echo $obj->location;
Return me https:twitter.com