@ruslite

Почему не могу получить страницу?

Пытаюсь сделать авторизацию через курл. Но почему то $page возвращается пустым. Почему не вытаскивает страницу, что здесь может быть не так?

$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;
  • Вопрос задан
  • 249 просмотров
Пригласить эксперта
Ответы на вопрос 1
erniesto77
@erniesto77
oop, rb, py, php, js
Попробуй получить $page вот так (у меня возвратилась)
$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);


UPD: если все равно пусто, то возможно расширение openssl не работает. В php.ini должно быть что то вроде этого (если windows):
extension=php_openssl.dll
allow_url_include = On
Ответ написан
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы