Answer the question
In order to leave comments, you need to log in
Why can't I get the page?
I'm trying to authorize via curl. But for some reason $page is returned empty. Why doesn't it pull out the page, what could be wrong here?
$url="https://instagram.com/accounts/login/";
$login="sdfwefef";
$pass="grergrgrg";
$page = file_get_contents($url);
$content = preg_match('<input type="hidden" name="csrfmiddlewaretoken" value="(.*?)">', $page, $found);
echo $found[1];
$key = $found[1];
$ch = curl_init();
if(strtolower((substr($url,0,5))=='https')) { // если соединяемся с https
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
}
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_REFERER, $url);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,"login=".$login."&pass=".$pass."&csrfmiddlewaretoken=".$key);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (Windows; U; Windows NT 5.0; En; rv:1.8.0.2) Gecko/20070306 Firefox/1.0.0.4");
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_COOKIEJAR, $_SERVER['DOCUMENT_ROOT'].'/cookie.txt');
$result=curl_exec($ch);
if(strpos($result,"Location: index.php")===false) die('Login incorrect');
curl_close($ch);
return $result;
Answer the question
In order to leave comments, you need to log in
Try to get $page like this (I got it back)
$context = stream_context_create(array("http"=>array(
"method" => "GET",
"header" => "Accept: text/*, */*\r\n",
"ignore_errors" => true,
)));
$page = file_get_contents("https://instagram.com/accounts/login/", false, $context);
extension=php_openssl.dll
allow_url_include = On
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question