Good evening.

Could not be authenticated using cURL. It seems to be doing everything right, but still does not allow.

Here is the site - http://www.vezetvsem.ru/listing Here is the authorization form - https://auth.vezetvsem.ru/auth/login

There are no hidden fields. Login / password are correct. For the test, you can use these: Login: 6kp5228wi4@kismail.ru Pass: w33q5u8t

After testing the code, we get the code from the unauthorized page.

<? function login($url,$login,$pass){ $ch = curl_init(); if(strtolower((substr($url,0,5))=='https')) { // если соединяемся с https //моя вставка curl_setopt($ch, CURLOPT_COOKIESESSION, true); //моя вставка 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 будет выводить подробные сообщения о всех производимых действиях curl_setopt($ch, CURLOPT_VERBOSE, 1); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_POSTFIELDS,"username=".$login."&password=".$pass); curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.87 Safari/537.36"); curl_setopt($ch, CURLOPT_HEADER, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); echo "username=".$login."&password=".$pass; //сохранять полученные COOKIE в файл curl_setopt($ch, CURLOPT_COOKIEJAR, $_SERVER['DOCUMENT_ROOT'].'/cookie.txt'); $result=curl_exec($ch); // Убеждаемся что произошло перенаправление после авторизации if(strpos($result,"Location: home.php")===false) die('Login incorrect'); curl_close($ch); return $result; } // чтение страницы после авторизации function Read($url){ $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_COOKIESESSION, true); // откуда пришли на эту страницу curl_setopt($ch, CURLOPT_REFERER, $url); //запрещаем делать запрос с помощью POST и соответственно разрешаем с помощью GET curl_setopt($ch, CURLOPT_POST, 0); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); //отсылаем серверу COOKIE полученные от него при авторизации curl_setopt($ch, CURLOPT_COOKIEFILE, $_SERVER['DOCUMENT_ROOT'].'/cookie.txt'); 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"); $result = curl_exec($ch); curl_close($ch); return $result; } $urlAut = "https://auth.vezetvsem.ru/auth/login"; login($urlAut,"6kp5228wi4@kismail.ru","w33q5u8t"); $page = Read("http://www.vezetvsem.ru/listing"); echo $page; ?> 
  • 2
    they won't write code for you) on fl.ru - ikerya
  • So I do not ask the code to write for me. I ask you to specify what exactly is my mistake? The function is written according to the canons of textbooks from different sites. Authorization must take place, but in fact does not pass. Where to dig already and I do not know right. - Oleg
  • provide a username and password from vezetvsem can? - ikerya
  • @ikerya Of course. I just made a test for these tasks. Login 6kp5228wi4@kismail.ru Pass w33q5u8t I don’t understand why it doesn’t work, because substituting data for another site, where there are 2 more hidden fields (which is easy to extract in the same way), everything works. - Oleg
  • Why did you decide that it does not work? I return the authorized page. The question is why do you need it here? if(strpos($result,"Location: home.php")===false) die('Login incorrect'); - Vayas

2 answers 2

Thanks to users inspired to use a different function. The result is a code that works. Thank you very much for your help. I apologize for the bad code, I'm just a month self-taught.

  $ch = curl_init(); if(strtolower((substr($url,0,5))=='https')) { // если соединяемся с https //моя вставка curl_setopt($ch, CURLOPT_COOKIESESSION, true); //моя вставка 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 будет выводить подробные сообщения о всех производимых действиях curl_setopt($ch, CURLOPT_VERBOSE, 1); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_POSTFIELDS,"username=".$login."&password=".$pass); curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.87 Safari/537.36"); curl_setopt($ch, CURLOPT_HEADER, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //сохранять полученные COOKIE в файл curl_setopt($ch, CURLOPT_COOKIEJAR, $_SERVER['DOCUMENT_ROOT'].'/cookievezetvsem.txt'); $result=curl_exec($ch); // Убеждаемся что произошло перенаправление после авторизации //if(strpos($result,"Location: home.php")===false) die('Login incorrect'); // для чего нужен этот код и как он работает? curl_close($ch); return $result; } // чтение страницы после авторизации function Read($url){ $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_COOKIESESSION, true); // откуда пришли на эту страницу curl_setopt($ch, CURLOPT_REFERER, $url); //запрещаем делать запрос с помощью POST и соответственно разрешаем с помощью GET curl_setopt($ch, CURLOPT_POST, 0); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); //отсылаем серверу COOKIE полученные от него при авторизации curl_setopt($ch, CURLOPT_COOKIEFILE, $_SERVER['DOCUMENT_ROOT'].'/cookievezetvsem.txt'); curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.87 Safari/537.36"); $result = curl_exec($ch); curl_close($ch); return $result; } function mainParser( $url )// парсер с кукисами { $ch = curl_init( $url ); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // возвращает веб-страницу curl_setopt($ch, CURLOPT_COOKIESESSION, true); curl_setopt($ch, CURLOPT_HEADER, 0); // не возвращает заголовки curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); // переходит по редиректам curl_setopt($ch, CURLOPT_ENCODING, ""); // обрабатывает все кодировки curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.87 Safari/537.36"); // useragent curl_setopt($ch, CURLOPT_COOKIEFILE, $_SERVER['DOCUMENT_ROOT'].'/cookievezetvsem.txt'); //хотя тут скорей всего он не записывает, а после каждого прохода вновь обращается к этому файлу curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 120); // таймаут соединения curl_setopt($ch, CURLOPT_TIMEOUT, 120); // таймаут ответа curl_setopt($ch, CURLOPT_MAXREDIRS, 10); // останавливаться после 10-ого редиректа $content = curl_exec( $ch ); $err = curl_errno( $ch ); $errmsg = curl_error( $ch ); $header = curl_getinfo( $ch ); curl_close( $ch ); $header['errno'] = $err; $header['errmsg'] = $errmsg; $header['content'] = $content; return $header; } $urlAut = "https://auth.vezetvsem.ru/auth/login"; login($urlAut,"XXX","XXX"); //login($urlAut,"6kp5228wi4@kismail.ru","w33q5u8t"); // по непонятной причине, эта пара Login, пароль возвращает неавторизованную страницу, Почему, я не понимаю. //$result = Read("http://www.vezetvsem.ru/listing"); // по какой то причине эта функция не работает, почему, я пока не понимаю $result = mainParser("http://www.vezetvsem.ru/listing"); $page = $result['content']; echo $page; ?> 
  • 1. The Read () function returns an unauthorized page. An excellent useragent from the login () function was specified, 2. The data specified in the question stopped working. Someone has changed them, or the site has blocked an account due to exit from different places. Fortunately, the account was a test and registered on the invented data. 3. What is the line if (strpos ($ result, "Location: home.php") === false) die ('Login incorrect'); `and why it gives an error is not clear. - Oleg

Looked like sending a request. it is sent by the Post method

Request URL:https://auth.vezetvsem.ru/auth/login Request Method:POST

and you are trying to feed him data GET th.

The login field is transmitted along with the form, this value does not need to be changed. username:6kp5228wi4@kismail.ru password:w33q5u8t login:Войти

try this:

  $data = array('username' => username, 'password' => password, login =>Войти); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_COOKIESESSION, true); curl_setopt($ch, CURLOPT_REFERER, $url); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data)); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_COOKIEFILE, $_SERVER['DOCUMENT_ROOT'].'/cookie.txt'); 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"); $result = curl_exec($ch); 
  • Unfortunately, you are mistaken. Here is the header of the transmitted POST form by the request dropbox.com/s/wju4htlxnl7dd13/ ... At the very bottom there is just what is being transmitted by the browser. The solution was found by substituting a slightly modified code from another function. I will unsubscribe below. But thank you so much for your time. - Oleg
  • @ Oleg, I probably don’t agree with you that I was wrong :) dropbox.com/s/rkekas3ohjfpu9r/auth.png?dl=0 there are 2 authorization forms, that's why it turned out - Bogdan Gudyma
  • totally agree with you. It is not clear why the second handicap is needed. As I will learn a mat I will try to understand In any case, again, thank you very much for your time. - Oleg