Advertisement
Guest User

Untitled

a guest
Jun 30th, 2017
289
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.52 KB | None | 0 0
  1. <?php
  2. global $usuario;
  3. $usuario = "universohumor2"; // your twitter account username
  4.  
  5. $ch = curl_init ();
  6.  
  7. /**
  8.  * ************************************ COMIENZAN LAS LLAMADAS A FUNCIONES ************************************
  9.  */
  10. /**
  11.  * ************************************************************************************************************
  12.  */
  13.  
  14. $vector_retorno = logueo_twitter ( $ch );
  15.  
  16. /**
  17.  * ***************************************************************************************************************
  18.  */
  19. function logueo_twitter($ch) {
  20.    
  21.     // $ch = curl_init();
  22.     global $usuario;
  23.    
  24.     $sTarget = "https://twitter.com";
  25.    
  26.     curl_setopt ( $ch, CURLOPT_URL, $sTarget );
  27.     curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, true );
  28.     curl_setopt ( $ch, CURLOPT_SSL_VERIFYPEER, false );
  29.     curl_setopt ( $ch, CURLOPT_SSL_VERIFYHOST, false );
  30.     curl_setopt ( $ch, CURLOPT_USERAGENT, $_SERVER ['HTTP_USER_AGENT'] );
  31.     curl_setopt ( $ch, CURLOPT_COOKIEFILE, "/tmp/cookie" . $usuario . "_tweet.txt" );
  32.     curl_setopt ( $ch, CURLOPT_COOKIESESSION, true );
  33.     curl_setopt ( $ch, CURLOPT_REFERER, $sTarget );
  34.     curl_setopt ( $ch, CURLOPT_HEADER, TRUE );
  35.    
  36.     $html = curl_exec ( $ch );
  37.     if (curl_errno ( $ch )) {
  38.         throw new RuntimeException ( 'curl_exec error. errno:' . curl_errno ( $c ) . '. error:' . curl_error ( $ch ) );
  39.     }
  40.     $domd = @DOMDocument::loadHTML ( $html );
  41.     $xpath = new DOMXPath ( $domd );
  42.     $authenticity_token = $xpath->query ( "//input[@name='authenticity_token']" )->item ( 0 )->getAttribute ( "value" );
  43.     $username = $usuario;
  44.     $password = "password"; // your twitter account password
  45.     $sPost = http_build_query ( array (
  46.             'session' => array (
  47.                     'username_or_email' => $username,
  48.                     'password' => $password
  49.             ),
  50.             'return_to_ssl' => true,
  51.             'scribe_log' => '',
  52.             'redirect_after_login' => '/',
  53.             'authenticity_token' => $authenticity_token
  54.     ) );
  55.     $sTarget = "https://twitter.com/sessions";
  56.    
  57.     curl_setopt ( $ch, CURLOPT_URL, $sTarget );
  58.     curl_setopt ( $ch, CURLOPT_POST, true );
  59.     curl_setopt ( $ch, CURLOPT_POSTFIELDS, $sPost );
  60.     curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, true );
  61.     curl_setopt ( $ch, CURLOPT_USERAGENT, $_SERVER ['HTTP_USER_AGENT'] );
  62.     curl_setopt ( $ch, CURLOPT_HEADER, TRUE );
  63.     curl_setopt ( $ch, CURLOPT_FOLLOWLOCATION, 1 );
  64.     // display server response
  65.     $htmldos = curl_exec ( $ch );
  66.    
  67.     // echo $htmldos;
  68.    
  69.     if (curl_errno ( $ch )) {
  70.         echo 'error:' . curl_error ( $ch );
  71.     }
  72.     $vector ["sPost"] = $sPost;
  73.     $vector ["authenticity_token"] = $authenticity_token;
  74.     return $vector;
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement