Faced a problem: you need to move through curl after authorization on the site on the internal admin pages, log in - write cookies, then throws on the main admin panel, then I can not reach other pages, writes Error in exception handler. I can not understand what the problem is, here is the code:

 //получаю токен $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'https://www.example.ru/auth/login'); curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt'); //curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookie.txt'); curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:35.0) Gecko/20100101 Firefox/35.0'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HEADER, 1); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); $pageLogin = curl_exec($ch); curl_close($ch); $token = (new DOMXPath(@DOMDocument::loadHTML($pageLogin)))->query("//input[@name='_token']")->item(0)->getAttribute("value"); $postFields['_token'] = $token; $postFields['email'] = $email; $postFields['password'] = $password; $post = ''; foreach ($postFields as $key => $value) { $post .= $key . '=' . urlencode($value) . '&'; } $post = substr($post, 0, -1); //авторизируюсь с токеном $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'https://www.example.ru/auth/login'); curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:35.0) Gecko/20100101 Firefox/35.0'); curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookie.txt'); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $post); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); $page = curl_exec($ch); // make request curl_close($ch); $postFields = array( '_token' => $token, 'type' => $data['user_type'], ); foreach ($postFields as $key => $value) { $post .= $key . '=' . urlencode($value) . '&'; } $post = substr($post, 0, -1); //отправляю другой пост на другую страницу $ch = curl_init(); $url2 = 'https://www.example.ru/post/create'; curl_setopt($ch, CURLOPT_URL, $url2); curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:35.0) Gecko/20100101 Firefox/35.0'); curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookie.txt'); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $post); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); $page = curl_exec($ch); // make request curl_close($ch); 
  • most likely error on the server side (site) - Naumov
  • @Naumov through the browser works fine, and through curl - an error, is there any idea what could cause such an error? - Denis
  • Or completely reproduce the browser, that is, the user agent, cookie, headers, etc. - Naumov
  • Either watch the logs on the site server, what is happening there - Naumov
  • Either work on the site via javascript - Dmitry Kozlov

0