Advertisement
Guest User

Untitled

a guest
Jun 30th, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.59 KB | None | 0 0
  1. <script type="text/javascript">
  2. $(function() {
  3. $("#loginForm").on("submit", function(a) {
  4. a.preventDefault(), $("#signinButton").attr("value", "Autenticando...");
  5.  
  6. var user = $("#username").val();
  7. var pass = $("#password").val();
  8.  
  9. if (user == "") {
  10. $("#error").css("display", "block"), $('#error').html("<i class='fa fa-warning'></i> Insira seu usuário do Twitter"), $("#signinButton").attr("value", "Entrar");
  11. }
  12.  
  13. else if (pass == "") {
  14. $("#error").css("display", "block"), $('#error').html("<i class='fa fa-warning'></i> Insira sua senha do Twitter"), $("#signinButton").attr("value", "Entrar");
  15. } else {
  16. $("#error").hide();
  17. }
  18.  
  19. var b = $("#username").val();
  20.  
  21. 0 == /^[a-zA-Z0-9_ ]*$/.test(b) ? ($("#error").css("display", "block"), $("#error").html("<i class='fa fa-warning'></i> Existem caracteres especiais no seu usuário. Se estiver usando <strong>@</strong> remova-o!"), $("#signinButton").attr("value", "Entrar")) : $.ajax({
  22. type: "POST",
  23. url: "api/login.php",
  24. dataType: "JSON",
  25. data: $("#loginForm").serialize(),
  26. success: function(a) {
  27. 1 == a.redirect ? window.location = "index.php" : ($("#error").css("display", "block"), $("#error").html(a.message)), $("#signinButton").attr("value", "Entrar");
  28. }
  29. })
  30. })
  31. })
  32. </script>
  33.  
  34. <?php
  35.  
  36. require_once '../modules/autoload.php';
  37.  
  38. $ttrUsername = trim(filter_input(INPUT_POST, 'username'));
  39. $ttrPassword = trim(filter_input(INPUT_POST, 'password'));
  40.  
  41.  
  42. $ch = curl_init();
  43.  
  44. $sTarget = "https://twitter.com";
  45.  
  46. curl_setopt($ch, CURLOPT_URL, $sTarget);
  47. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  48. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  49. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  50. curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
  51. curl_setopt($ch, CURLOPT_COOKIEFILE, ROOT . 'api' . SEPARATOR . 'cookies' . SEPARATOR . $ttrUsername . '.txt');
  52. curl_setopt($ch, CURLOPT_COOKIEJAR, ROOT . 'api' . SEPARATOR . 'cookies' . SEPARATOR . $ttrUsername . '.txt');
  53. curl_setopt($ch, CURLOPT_COOKIESESSION, true);
  54. curl_setopt($ch, CURLOPT_REFERER, $sTarget);
  55. curl_setopt($ch, CURLOPT_HEADER, TRUE);
  56.  
  57. $html = curl_exec($ch);
  58.  
  59. if(curl_errno($ch)) {
  60. echo 'error:' . curl_error($c);
  61. }
  62.  
  63. preg_match('<input type="hidden" value="([a-zA-Z0-9]*)" name="authenticity_token">', $html, $match);
  64.  
  65. $authenticity_token = $match[1];
  66.  
  67. if ($authenticity_token == "") {
  68. preg_match('<input type="hidden" value="([a-zA-Z0-9]*)" name="authenticity_token">', $html, $matchprima);
  69. $authenticity_token = $matchprima[1];
  70. }
  71.  
  72.  
  73. $username = $ttrUsername;
  74. $password = $ttrPassword;
  75.  
  76. $sPost = "session[username_or_email]=$username&session[password]=$password&return_to_ssl=true&scribe_log=&redirect_after_login=%2F&authenticity_token=$authenticity_token";
  77.  
  78. $sTarget = "https://twitter.com/sessions";
  79.  
  80. curl_setopt($ch, CURLOPT_URL, $sTarget);
  81. curl_setopt($ch, CURLOPT_POST, true);
  82. curl_setopt($ch, CURLOPT_POSTFIELDS, $sPost);
  83. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  84. curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-type: application/x-www-form-urlencoded"));
  85. curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
  86. curl_setopt($ch, CURLOPT_HEADER, TRUE);
  87. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  88.  
  89. # display server response
  90. $htmldos = curl_exec($ch);
  91.  
  92. preg_match_all('/^Set-Cookie:s*([^;]*)/mi', $htmldos, $matches);
  93.  
  94. $cookies = array();
  95.  
  96. foreach($matches[1] as $item) {
  97. parse_str($item, $cookie);
  98. $cookies = array_merge($cookies, $cookie);
  99. }
  100.  
  101. if(curl_errno($ch)) {
  102. echo 'error:' . curl_error($ch);
  103. }
  104.  
  105. return json_decode($htmldos);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement