Y
Y
Yury Alikaev2017-01-12 10:27:43
1C-Bitrix
Yury Alikaev, 2017-01-12 10:27:43

How to connect via CURL to the Bitrix admin panel?

Hello colleagues!
I've worked with Curl a lot, but I just can't get into the Bitrix admin panel via cURL. More precisely, I go to the start page of the admin panel (/bitrix/admin), but if I want to get, for example, data from the performance panel (/bitrix/admin/perfmon_panel.php), then zilch. What am I doing wrong?

$site_url = 'http://site.ru/bitrix/admin/perfmon_panel.php'; //URL панели производительности в админке  сайта на Битриксе
$post_var = 'AUTH_FORM=Y&TYPE=AUTH&USER_LOGIN=admin&USER_PASSWORD=qwerty123&Login=&USER_REMEMBER=Y&captcha_sid=&captcha_word=bca897af2d782ba894633b851ak35ff3&sessid=bda897af5d782ba194643b851af353f3'; //эти данные собираются путём парсинга формы авторизации, для простоты поместил их в одну переменную

$ch = curl_init(); 
curl_setopt($ch, CURLOPT_COOKIEJAR, $_SERVER['DOCUMENT_ROOT'].'/cookie.txt'); //куда сохранять cookie
curl_setopt($ch, CURLOPT_COOKIEFILE, $_SERVER['DOCUMENT_ROOT'].'/cookie.txt'); //откуда берем cookie
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);   // возвращаем веб-страницу 
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); // следуем за редиректами
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); 
curl_setopt($ch, CURLOPT_HEADER, false); //не выводим заголовки
curl_setopt($ch, CURLOPT_URL, $site_url); //URL сайта на Битриксе
curl_setopt($ch, CURLOPT_POST, true); //используем POST-запрос
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_var); //строка с POST-переменными (значения присвоены выше)

$text = curl_exec($ch); 
echo($text);
curl_close($ch);

In response, nothing is displayed on the page, except for the code:
<script type="text/javascript">window.onload=function(){top.BX.AUTHAGENT.setAuthResult(false);};</script>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ilya, 2017-01-12
@yury_alikaev

Good afternoon.
You say that you are successfully accessing the "admin panel start page", which means that you have already logged in without any problems. Hence the question - why are you sending a POST request then?
If you are logged in, then make a regular GET request at the desired URL and then you have to look further.
If, by the start page of the admin panel, you mean the authorization page (which is strange), then you should send a POST request to /bitrix/admin/, and not to bitrix/admin/perfmon_panel.php.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question