Login - PHP Online

Form of PHP Sandbox

Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php in the places where the PHP script should be executed.



Your result can be seen below.

Result of php executing





Full code of Login.php

  1. <?php
  2. header("Content-type:application/json");
  3.  
  4. error_reporting(0);
  5. set_time_limit(0);
  6. ignore_user_abort(1);
  7.  
  8.  
  9. function postRequest($ighost, $useragent, $url, $cookie = 0, $data = 0, $httpheader = array(), $proxy = 0, $userpwd = 0, $is_socks5 = 0)
  10. {
  11.         $url = $ighost 'https://i.instagram.com/api/v1/' . $url : $url;
  12.         $ch = curl_init($url);
  13.         curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
  14.         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  15.         curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  16.         curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  17.         curl_setopt($ch, CURLOPT_TIMEOUT, 20);
  18.         if($proxy) curl_setopt($ch, CURLOPT_PROXY, $proxy);
  19.         if($userpwd) curl_setopt($ch, CURLOPT_PROXYUSERPWD, $userpwd);
  20.         if($is_socks5) curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
  21.         if($httpheader) curl_setopt($ch, CURLOPT_HTTPHEADER, $httpheader);
  22.         curl_setopt($ch, CURLOPT_HEADER, 1);
  23.         if($cookie) curl_setopt($ch, CURLOPT_COOKIE, $cookie);
  24.         if ($data):
  25.                 curl_setopt($ch, CURLOPT_POST, 1);
  26.                 curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  27.         endif;
  28.         $response = curl_exec($ch);
  29.         $httpcode = curl_getinfo($ch);
  30.         if(!$httpcode) return false; else{
  31.                 $header = substr($response, 0, curl_getinfo($ch, CURLINFO_HEADER_SIZE));
  32.                 $body = substr($response, curl_getinfo($ch, CURLINFO_HEADER_SIZE));
  33.                 curl_close($ch);
  34.                 return array($header, $body);
  35.         }
  36. }
  37.  
  38. function generateSignature($data)
  39. {
  40.         return hash_hmac('sha256', $data, '109513c04303341a7daf27bb41b268e633b30dcc65a3fe14503f743176113869');
  41. }
  42.  
  43. function generateSignatureForPost($data)
  44. {
  45.         return 'ig_sig_key_version=4&signed_body='.generateSignature($data).'.'.urlencode($data);
  46. }
  47.  
  48. function generateDeviceId()
  49. {
  50.         $megaRandomHash = md5(number_format(microtime(true), 7, '', ''));
  51.         return 'android-'.substr($megaRandomHash, 16);
  52. }
  53.  
  54. function generateUseragent()
  55. {
  56.         return 'Instagram 27.0.0.7.97 Android (18/4.3; 320dpi; 720x1280; Xiaomi; HM 1SW; armani; qcom; en_US)';
  57. }
  58.  
  59. function get_csrftoken(){
  60.         $fetch = postRequest('si/fetch_headers/', null, null);
  61.         $header = $fetch[0];
  62.         if (!preg_match('#Set-Cookie: csrftoken=([^;]+)#', $fetch[0], $token)) {
  63.                 return json_encode(array('result' => false, 'content' => 'Missing csrftoken'));
  64.         } else {
  65.                 return substr($token[0], 22);
  66.         }
  67. }
  68.  
  69. function generateUUID($keepDashes = true)
  70. {
  71.         $uuid = sprintf(
  72.         '%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
  73.         mt_rand(0, 0xffff),
  74.         mt_rand(0, 0xffff),
  75.         mt_rand(0, 0xffff),
  76.         mt_rand(0, 0x0fff) | 0x4000,
  77.         mt_rand(0, 0x3fff) | 0x8000,
  78.         mt_rand(0, 0xffff),
  79.         mt_rand(0, 0xffff),
  80.         mt_rand(0, 0xffff)
  81.     );
  82.  
  83.     return $keepDashes $uuid : str_replace('-', '', $uuid);
  84. }
  85.  
  86.  
  87. function LoginInstagram($username, $password)
  88. {
  89.         $postData = json_encode([
  90.                 'phone_id' => generateUUID(true),
  91.                 '_csrftoken' => get_csrftoken(),
  92.                 'username' => $username,
  93.                 'guid' => generateUUID(true),
  94.                 'device_id' => generateUUID(true),
  95.                 'password' => $password,
  96.                 'login_attempt_count' => 0
  97.         ]);
  98.        
  99.         $instagramLogin = postRequest(1, generateUseragent(), 'accounts/login/', 0, generateSignatureForPost($postData), "122.72.18.61:80");
  100.         $getHeader      = $instagramLogin[0];
  101.         $instagramLogin =  json_decode($instagramLogin[1]);
  102.        
  103.         if($instagramLogin->status == 'ok')
  104.         {
  105.             preg_match_all('%Set-Cookie: (.*?);%', $getHeader, $d);$cookies = '';
  106.             for($o = 0; $o < count($d[0]); $o++)$cookies.= $d[1][$o].";";
  107.             $array = json_encode(['status' => 'ok', 'cookies' => $cookies, 'device_id' => generateDeviceId(), 'user_id' => $instagramLogin->logged_in_user->pk, 'useragent' => generateUseragent()]);
  108.         }
  109.         else
  110.         {
  111.             $array = json_encode(['status' => 'fail', 'message' => $instagramLogin->message]);
  112.         }
  113.        
  114.         return $array;
  115. }
  116.  
  117. $username = 'adindaath';
  118. $password = 'lolipop1902';
  119. $login = LoginInstagram($username, $password);
  120. print_r($login);
File Description
  • Login
  • PHP Code
  • 11 Aug-2018
  • 3.68 Kb
You can Share it: