Advertisement
Guest User

curl login 2

a guest
Oct 14th, 2017
447
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.40 KB | None | 0 0
  1. <?php
  2.     $username = "KULLANICIADIM";
  3.     $password = "ŞİFREM";
  4.     $useragent = "Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.13) Gecko/20101206 Ubuntu/10.10 (maverick) Firefox/3.6.13";
  5.     $cookie=$username.".txt";
  6.  
  7.     $url="https://instagram.com/accounts/login/?force_classic_login";
  8.  
  9.     $ch  = curl_init();
  10.     curl_setopt($ch, CURLOPT_URL, $url);
  11.     curl_setopt($ch, CURLOPT_COOKIEJAR, dirname(__FILE__)."/".$cookie);
  12.     curl_setopt($ch, CURLOPT_COOKIEFILE, dirname(__FILE__)."/".$cookie);
  13.     curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
  14.     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  15.     curl_setopt($ch, CURLOPT_HEADER, 1);
  16.     curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  17.  
  18.     $page = curl_exec($ch);
  19.  
  20.     // try to find the actual login form
  21.     if (!preg_match('/<form method="POST" id="login-form" class="adjacent".*?<\/form>/is', $page, $form)) {
  22.         die('Failed to find log in form!');
  23.     }
  24.  
  25.     $form = $form[0];
  26.  
  27.     // find the action of the login form
  28.     if (!preg_match('/action="([^"]+)"/i', $form, $action)) {
  29.         die('Failed to find login form url');
  30.     }
  31.  
  32.     $url2 = $action[1]; // this is our new post url
  33.     // find all hidden fields which we need to send with our login, this includes security tokens
  34.     $count = preg_match_all('/<input type="hidden"\s*name="([^"]*)"\s*value="([^"]*)"/i', $form, $hiddenFields);
  35.  
  36.     $postFields = array();
  37.  
  38.     // turn the hidden fields into an array
  39.     for ($i = 0; $i < $count; ++$i) {
  40.         $postFields[$hiddenFields[1][$i]] = $hiddenFields[2][$i];
  41.     }
  42.  
  43.     // add our login values
  44.     $postFields['username'] = $username;
  45.     $postFields['password'] = $password;
  46.  
  47.     $post = '';
  48.  
  49.     // convert to string, this won't work as an array, form will not accept multipart/form-data, only application/x-www-form-urlencoded
  50.     foreach($postFields as $key => $value) {
  51.         $post .= $key . '=' . urlencode($value) . '&';
  52.     }
  53.  
  54.     $post = substr($post, 0, -1);
  55.  
  56.     // set additional curl options using our previous options
  57.     curl_setopt($ch, CURLOPT_URL, "https://instagram.com/".$url2);
  58.     curl_setopt($ch, CURLOPT_REFERER, $url);
  59.     curl_setopt($ch, CURLOPT_POST, 1);
  60.     curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
  61.    $page = curl_exec($c);
  62.     curl_close($c);
  63.     $page = str_replace("<head>","<head>".PHP_EOL."<base href='https://www.instagram.com/'>",$page);
  64.     echo $page;
  65.  
  66. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement