M
M
maddog6702016-04-19 21:10:32
PHP
maddog670, 2016-04-19 21:10:32

What is the reason for The change you wanted was rejected error?

Good evening. I need a parser with authorization on the site. At the authorization stage, I stalled. Writes an error The change you wanted was rejected. Maybe you tried to change something you didn't have access to.
e60b3c4795e04622b5850432576a518f.png
On the authorization page https://www.allbestbets.ru/users/sign_in in the source there is a meta tag csrf-token and in the form itself authenticity_token . Who can explain what is my mistake. I am attaching the code.

Class Parse {

    public function token($url){
        $html = file_get_contents($url);
        preg_match('/<meta name=\"csrf-token\" content=\"(.*)\"/iu', $html, $authCode);
        if(!empty($authCode)) return urlencode($authCode[1]);
    }

    public function authSite($cfg){
        $userAgent = explode("\n", $cfg['useragents']);
        $random = mt_rand(0, $cfg['count_ua']);
        //$headers = explode("\n", $cfg['headers']);

        $ch = curl_init($cfg['sign_in']);

        curl_setopt($ch, CURLOPT_USERAGENT, $userAgent[$random]);
        curl_setopt($ch, CURLOPT_COOKIEJAR, ENGINE_DIR.'/data/'.$cfg['cookie']);
        curl_setopt($ch, CURLOPT_COOKIEFILE, ENGINE_DIR.'/data/'.$cfg['cookie']);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array(
            'Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
            'Content-Type:application/x-www-form-urlencoded',
            'Origin:https://www.allbestbets.ru',
            'Referer:https://www.allbestbets.ru/users/sign_in'
        ));

        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);

        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

        $postData = "utf8=%E2%9C%93&authenticity_token=".$this->token($cfg['sign_in'])."&abb_user%5Bemail%5D=".$cfg['email']."&abb_user%5Bpassword%5D=".$cfg['password']."&abb_user%5Bremember_me%5D=1";
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);

        $data = curl_exec($ch);
        echo $data;
        curl_close($ch);
    }
}
$pr = new Parse();
$pr->authSite($parserCfg);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
maddog670, 2016-04-21
@maddog670

I decided myself. Thanks to all.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question