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.
Result of php executing
Full code of Login.php
- <?php
- header("Content-type:application/json");
- error_reporting(0);
- set_time_limit(0);
- ignore_user_abort(1);
- function postRequest($ighost, $useragent, $url, $cookie = 0, $data = 0, $httpheader = array(), $proxy = 0, $userpwd = 0, $is_socks5 = 0)
- {
- $url = $ighost ? 'https://i.instagram.com/api/v1/' . $url : $url;
- $ch = curl_init($url);
- curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
- curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
- curl_setopt($ch, CURLOPT_TIMEOUT, 20);
- if($proxy) curl_setopt($ch, CURLOPT_PROXY, $proxy);
- if($userpwd) curl_setopt($ch, CURLOPT_PROXYUSERPWD, $userpwd);
- if($is_socks5) curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
- if($httpheader) curl_setopt($ch, CURLOPT_HTTPHEADER, $httpheader);
- curl_setopt($ch, CURLOPT_HEADER, 1);
- if($cookie) curl_setopt($ch, CURLOPT_COOKIE, $cookie);
- if ($data):
- curl_setopt($ch, CURLOPT_POST, 1);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
- endif;
- $response = curl_exec($ch);
- $httpcode = curl_getinfo($ch);
- if(!$httpcode) return false; else{
- $header = substr($response, 0, curl_getinfo($ch, CURLINFO_HEADER_SIZE));
- $body = substr($response, curl_getinfo($ch, CURLINFO_HEADER_SIZE));
- curl_close($ch);
- return array($header, $body);
- }
- }
- function generateSignature($data)
- {
- return hash_hmac('sha256', $data, '109513c04303341a7daf27bb41b268e633b30dcc65a3fe14503f743176113869');
- }
- function generateSignatureForPost($data)
- {
- return 'ig_sig_key_version=4&signed_body='.generateSignature($data).'.'.urlencode($data);
- }
- function generateDeviceId()
- {
- $megaRandomHash = md5(number_format(microtime(true), 7, '', ''));
- return 'android-'.substr($megaRandomHash, 16);
- }
- function generateUseragent()
- {
- return 'Instagram 27.0.0.7.97 Android (18/4.3; 320dpi; 720x1280; Xiaomi; HM 1SW; armani; qcom; en_US)';
- }
- function get_csrftoken(){
- $fetch = postRequest('si/fetch_headers/', null, null);
- $header = $fetch[0];
- if (!preg_match('#Set-Cookie: csrftoken=([^;]+)#', $fetch[0], $token)) {
- return json_encode(array('result' => false, 'content' => 'Missing csrftoken'));
- } else {
- return substr($token[0], 22);
- }
- }
- function generateUUID($keepDashes = true)
- {
- $uuid = sprintf(
- '%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
- mt_rand(0, 0xffff),
- mt_rand(0, 0xffff),
- mt_rand(0, 0xffff),
- mt_rand(0, 0x0fff) | 0x4000,
- mt_rand(0, 0x3fff) | 0x8000,
- mt_rand(0, 0xffff),
- mt_rand(0, 0xffff),
- mt_rand(0, 0xffff)
- );
- return $keepDashes ? $uuid : str_replace('-', '', $uuid);
- }
- function LoginInstagram($username, $password)
- {
- $postData = json_encode([
- 'phone_id' => generateUUID(true),
- '_csrftoken' => get_csrftoken(),
- 'username' => $username,
- 'guid' => generateUUID(true),
- 'device_id' => generateUUID(true),
- 'password' => $password,
- 'login_attempt_count' => 0
- ]);
- $instagramLogin = postRequest(1, generateUseragent(), 'accounts/login/', 0, generateSignatureForPost($postData), "122.72.18.61:80");
- $getHeader = $instagramLogin[0];
- $instagramLogin = json_decode($instagramLogin[1]);
- if($instagramLogin->status == 'ok')
- {
- preg_match_all('%Set-Cookie: (.*?);%', $getHeader, $d);$cookies = '';
- for($o = 0; $o < count($d[0]); $o++)$cookies.= $d[1][$o].";";
- $array = json_encode(['status' => 'ok', 'cookies' => $cookies, 'device_id' => generateDeviceId(), 'user_id' => $instagramLogin->logged_in_user->pk, 'useragent' => generateUseragent()]);
- }
- else
- {
- $array = json_encode(['status' => 'fail', 'message' => $instagramLogin->message]);
- }
- return $array;
- }
- $username = 'adindaath';
- $password = 'lolipop1902';
- $login = LoginInstagram($username, $password);
- print_r($login);
File Description
- Login
- PHP Code
- 11 Aug-2018
- 3.68 Kb
You can Share it:
Latest PHP Pastes