N
N
Nikolai Gavrilovich2018-03-29 22:47:19
PHP
Nikolai Gavrilovich, 2018-03-29 22:47:19

How to log in with multi curl?

Good day. There is a parser script that goes through the pages using curl, in general, a regular parser.
Below is the function of getting the page, and if the authorization request is not authorized

function isAuth( $data ){
    return preg_match('#<a href="/site/logout" data-method="post">Logout</a>#',$data);
}
function request($url){
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_COOKIESESSION, true); 
    curl_setopt($curl, CURLOPT_COOKIEFILE, "cookiefile"); 
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); 
    curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); 
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
    curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 6.0; ru; rv:1.9.1.3) Gecko/20090824 Firefox/3.5.3'); 
    curl_setopt($curl, CURLOPT_URL, $url); 
    $data = curl_exec($curl);
    if(isAuth($data)){
        return $data;
    } else {
        preg_match('/<input type="hidden" name="_csrf" value="(.*)"/Uis',$data, $login_csrf);
        $login_csrf = $login_csrf[1];
        $post = "LoginForm[username]=****&LoginForm[password]=*****&LoginForm[rememberMe]=1&_csrf=".$login_csrf."";
        curl_setopt($curl, CURLOPT_URL, 'http://yoursite.com/login');
        curl_setopt($curl, CURLOPT_POSTFIELDS, $post);
        $html = curl_exec($curl);
        unset($curl);
        return $html;
    }
}

Authorization is implemented in the script, the time has come and it is necessary to transfer the script to multi curl. I've been sitting for the third day, but I just can't log in to multi curl. Get on the right path. I tried with saving cookies, a separate curl, but apparently the knowledge is not enough, either nothing or error 400 "Failed to verify the data being sent"

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question