Advertisement
Guest User

Untitled

a guest
May 17th, 2017
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.09 KB | None | 0 0
  1. <?php
  2. //once u make bots, set them on a while loop (or foreach file in dir)
  3. //this will login to them, and grab their session ids so u can play with them at any time ;)
  4. $username = "your bot username";
  5. $password = "your bot pw";
  6. $useragent = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/50.0.2661.102 Chrome/50.0.2661.102 Safari/537.36";
  7. $cookie=$username.".txt";
  8. @unlink(dirname(__FILE__)."/".$cookie);
  9. $url="https://www.instagram.com/accounts/login/?force_classic_login";
  10. $ch  = curl_init();        
  11. $arrSetHeaders = array(
  12.     "User-Agent: $useragent",
  13.     'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
  14.     'Accept-Language: en-US,en;q=0.5',
  15.     'Accept-Encoding: deflate, br',
  16.     'Connection: keep-alive',
  17.     'cache-control: max-age=0',
  18. );
  19. curl_setopt($ch, CURLOPT_HTTPHEADER, $arrSetHeaders);        
  20. curl_setopt($ch, CURLOPT_URL, $url);
  21. curl_setopt($ch, CURLOPT_COOKIEJAR, dirname(__FILE__)."/".$cookie);
  22. curl_setopt($ch, CURLOPT_COOKIEFILE, dirname(__FILE__)."/".$cookie);
  23. curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
  24. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  25. curl_setopt($ch, CURLOPT_HEADER, 1);
  26. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  27. $page = curl_exec($ch);
  28. curl_close($ch);          
  29. if (!preg_match('/<form method="POST" id="login-form" class="adjacent".*?<\/form>/is', $page, $form)) {
  30.     die('Failed to find log in form!');
  31. }
  32. $form = $form[0];
  33. if (!preg_match('/action="([^"]+)"/i', $form, $action)) {
  34.     die('Failed to find login form url');
  35. }
  36.  
  37. $url2 = $action[1];
  38. $count = preg_match_all('/<input type="hidden"\s*name="([^"]*)"\s*value="([^"]*)"/i', $form, $hiddenFields);
  39.  
  40. $postFields = array();
  41. for ($i = 0; $i < $count; ++$i) {
  42.     $postFields[$hiddenFields[1][$i]] = $hiddenFields[2][$i];
  43. }
  44. $postFields['username'] = $username;
  45. $postFields['password'] = $password;  
  46.  
  47. $post = '';
  48. foreach($postFields as $key => $value) {
  49.     $post .= $key . '=' . urlencode($value) . '&';
  50. }
  51.  
  52. $post = substr($post, 0, -1);  
  53.  
  54. preg_match_all('/^Set-Cookie:\s*([^;]*)/mi', $page, $matches);
  55.  
  56. $cookieFileContent = '';
  57.  
  58. foreach($matches[1] as $item) {
  59.     $cookieFileContent .= "$item; ";
  60. }
  61.  
  62. $cookieFileContent = rtrim($cookieFileContent, '; ');
  63. $cookieFileContent = str_replace('sessionid=; ', '', $cookieFileContent);
  64.  
  65. $oldContent = file_get_contents(dirname(__FILE__)."/".$cookie);
  66. $oldContArr = explode("\n", $oldContent);
  67.  
  68. if(count($oldContArr)){
  69.     foreach($oldContArr as $k => $line){
  70.         if(strstr($line, '# ')){
  71.             unset($oldContArr[$k]);
  72.         }
  73.     }
  74.     $newContent = implode("\n", $oldContArr);
  75.     $newContent = trim($newContent, "\n");
  76.  
  77.     file_put_contents(
  78.         dirname(__FILE__)."/".$cookie,
  79.         $newContent
  80.     );    
  81. }
  82.  
  83. $arrSetHeaders = array(
  84.     'origin: https://www.instagram.com',
  85.     'authority: www.instagram.com',
  86.     'upgrade-insecure-requests: 1',
  87.     'Host: www.instagram.com',
  88.     "User-Agent: $useragent",
  89.     'content-type: application/x-www-form-urlencoded',
  90.     'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
  91.     'Accept-Language: en-US,en;q=0.5',
  92.     'Accept-Encoding: deflate, br',
  93.     "Referer: $url",
  94.     "Cookie: $cookieFileContent",
  95.     'Connection: keep-alive',
  96.     'cache-control: max-age=0',
  97. );
  98.  
  99. $ch  = curl_init();
  100. curl_setopt($ch, CURLOPT_COOKIEJAR, dirname(__FILE__)."/".$cookie);
  101. curl_setopt($ch, CURLOPT_COOKIEFILE, dirname(__FILE__)."/".$cookie);
  102. curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
  103. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  104. curl_setopt($ch, CURLOPT_HEADER, 1);
  105. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  106. curl_setopt($ch, CURLOPT_HTTPHEADER, $arrSetHeaders);    
  107. curl_setopt($ch, CURLOPT_URL, $url);
  108. curl_setopt($ch, CURLOPT_REFERER, $url);
  109. curl_setopt($ch, CURLOPT_POST, true);
  110. curl_setopt($ch, CURLOPT_POSTFIELDS, $post);        
  111.  
  112. $page = curl_exec($ch);
  113.  
  114.  
  115. preg_match_all('/^Set-Cookie:\s*([^;]*)/mi', $page, $matches);
  116. $cookies = array();
  117. foreach($matches[1] as $item) {
  118.     parse_str($item, $cookie1);
  119.     $cookies = array_merge($cookies, $cookie1);
  120. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement