Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require_once dirname(__DIR__) . '/settings/Settings.php';
- function login($username, $password)
- {
- $cookie = '';
- $location = '';
- $request = curl_init();
- curl_setopt_array($request, array(
- CURLOPT_URL => 'https://twitter.com',
- CURLOPT_CUSTOMREQUEST => 'GET',
- CURLOPT_RETURNTRANSFER => true,
- CURLOPT_SSL_VERIFYPEER => false,
- CURLOPT_SSL_VERIFYHOST => false,
- CURLOPT_HEADER => true,
- CURLOPT_USERAGENT => $_SERVER['HTTP_USER_AGENT'],
- CURLOPT_COOKIEJAR => getcwd() . '/cookies/' . $username . '.txt',
- CURLOPT_HEADERFUNCTION => function($curl, $header) use (&$cookie)
- {
- if (stripos($header, 'Set-Cookie:') === 0)
- {
- if (preg_match('/^Set-Cookie: \s*([^;]*)/i', $header, $matches))
- {
- $cookie .= $matches[1] . '; ';
- }
- }
- return strlen($header);
- }
- ));
- $response = curl_exec($request);
- preg_match('/value="(.*?)" name="authenticity_token"/', $response, $matches);
- $authenticity_token = $matches[1];
- $post = http_build_query(array(
- 'session' => array(
- 'username_or_email' => $username,
- 'password' => $password
- ),
- 'return_to_ssl' => true,
- 'scribe_log' => '',
- 'redirect_after_login' => '/',
- 'authenticity_token' => $authenticity_token,
- 'remember_me' => 1
- ));
- curl_setopt_array($request, array(
- CURLOPT_URL => 'https://twitter.com/sessions',
- CURLOPT_CUSTOMREQUEST => 'POST',
- CURLOPT_POSTFIELDS => $post,
- CURLOPT_RETURNTRANSFER => true,
- CURLOPT_SSL_VERIFYPEER => false,
- CURLOPT_SSL_VERIFYHOST => false,
- CURLOPT_COOKIE => $cookie,
- CURLOPT_USERAGENT => $_SERVER['HTTP_USER_AGENT'],
- CURLOPT_HTTPHEADER => array(
- 'accept-language: pt-BR,pt;q=0.8,en-US;q=0.6,en;q=0.4',
- 'content-type: application/x-www-form-urlencoded',
- 'origin: https://twitter.com',
- 'referer: https://twitter.com/login',
- ),
- CURLOPT_HEADERFUNCTION => function($curl, $header) use (&$cookie, &$location)
- {
- if (stripos($header, 'Set-Cookie:') === 0)
- {
- if (preg_match('/^Set-Cookie: \s*([^;]*)/i', $header, $matches))
- {
- $cookie .= $matches[1] . '; ';
- }
- }
- if (stripos($header, 'Location:') === 0)
- {
- $location = trim(str_ireplace('location: ', '', trim($header)));
- }
- return strlen($header);
- }
- ));
- $response = curl_exec($request);
- $_SESSION['login_cookies'] = $cookie;
- $cookie_array = explode('; ', $cookie);
- $_SESSION['cookie_array'] = $cookie_array;
- curl_close($request);
- $location = trim(explode('?', $location)[0], '/');
- switch ($location)
- {
- case 'https://twitter.com':
- echo json_encode(array(
- 'success' => true,
- 'message' => 'Logado com sucesso aguarde...'
- ));
- break;
- case 'https://twitter.com/account/access':
- echo json_encode(array(
- 'success' => false,
- 'message' => 'Sua conta está bloqueada entre no Twitter para desbloquea-la'
- ));
- break;
- case 'https://twitter.com/account/login_verification':
- echo json_encode(array(
- 'success' => false,
- 'message' => 'Sua conta exige verificação via 2FA'
- ));
- break;
- default:
- echo json_encode(array(
- 'success' => false,
- 'message' => 'Usuário e/ou Senha incorretos'
- ));
- break;
- }
- }
- if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] === 'POST')
- {
- $username = strip_tags(trim(filter_input(INPUT_POST, 'username')));
- $password = strip_tags(trim(filter_input(INPUT_POST, 'password')));
- if (empty($username))
- {
- echo json_encode(array(
- 'success' => false,
- 'message' => 'Informe seu usuário para continuar.'
- ));
- }
- elseif (empty($password))
- {
- echo json_encode(array(
- 'success' => false,
- 'message' => 'Informe sua senha para continuar.'
- ));
- }
- else
- {
- login($username, $password);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement