Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $username = "KULLANICIADIM";
- $password = "ŞİFREM";
- $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";
- $cookie=$username.".txt";
- $url="https://instagram.com/accounts/login/?force_classic_login";
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_COOKIEJAR, dirname(__FILE__)."/".$cookie);
- curl_setopt($ch, CURLOPT_COOKIEFILE, dirname(__FILE__)."/".$cookie);
- curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_HEADER, 1);
- curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
- $page = curl_exec($ch);
- // try to find the actual login form
- if (!preg_match('/<form method="POST" id="login-form" class="adjacent".*?<\/form>/is', $page, $form)) {
- die('Failed to find log in form!');
- }
- $form = $form[0];
- // find the action of the login form
- if (!preg_match('/action="([^"]+)"/i', $form, $action)) {
- die('Failed to find login form url');
- }
- $url2 = $action[1]; // this is our new post url
- // find all hidden fields which we need to send with our login, this includes security tokens
- $count = preg_match_all('/<input type="hidden"\s*name="([^"]*)"\s*value="([^"]*)"/i', $form, $hiddenFields);
- $postFields = array();
- // turn the hidden fields into an array
- for ($i = 0; $i < $count; ++$i) {
- $postFields[$hiddenFields[1][$i]] = $hiddenFields[2][$i];
- }
- // add our login values
- $postFields['username'] = $username;
- $postFields['password'] = $password;
- $post = '';
- // convert to string, this won't work as an array, form will not accept multipart/form-data, only application/x-www-form-urlencoded
- foreach($postFields as $key => $value) {
- $post .= $key . '=' . urlencode($value) . '&';
- }
- $post = substr($post, 0, -1);
- // set additional curl options using our previous options
- curl_setopt($ch, CURLOPT_URL, "https://instagram.com/".$url2);
- curl_setopt($ch, CURLOPT_REFERER, $url);
- curl_setopt($ch, CURLOPT_POST, 1);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
- $page = curl_exec($c);
- curl_close($c);
- $page = str_replace("<head>","<head>".PHP_EOL."<base href='https://www.instagram.com/'>",$page);
- echo $page;
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement