Answer the question
In order to leave comments, you need to log in
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;
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question