Submitting data into Instagram login page using Curl returns Bad Request

Viewed 72

I want to use PHP Curl to login into Instagram in web browser.

So I coded this:

<?php
$data = array(
    "username" => "my_username",
    "password" => "my_password",
    "submit" => "submit"
);

$url = "https://www.instagram.com/accounts/login/";
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_NOBODY, false); 
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt'); 
curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookie.txt'); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7.12) Gecko/20050915 Firefox/1.0.7");
curl_setopt($ch, CURLOPT_REFERER, $_SERVER['REQUEST_URI']);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);

$result = curl_exec($ch);
curl_close($ch);

echo $result;
?>

But when I try this, I get this:

HTTP/2 400 content-type: text/html; charset=utf-8 date: Sun, 17 Jul 2022 07:48:39 GMT content-length: 11 x-ig-origin-region: odn x-fb-trip-id: 1679558926 alt-svc: h3=":443"; ma=86400,h3-29=":443"; ma=86400 Bad request 

So I wonder, what's going wrong here?

Am I missing something as curl_setopt in the code?

Is this even possible (logging into Instagram using curl in a web browser)?

0 Answers
Related