S
S
siroper2021-02-12 21:15:10
PHP
siroper, 2021-02-12 21:15:10

Unable to log in with curl, why?

Hello. I'm trying to log in to the site using curl php (website on Bitrix) but I can't

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://www.site.ru/login/' );
curl_setopt($ch, CURLOPT_USERAGENT,'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/32.0.1700.107 Chrome/32.0.1700.107 Safari/537.36');
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_NOBODY, 1); 
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_COOKIEJAR, dirname(__FILE__).'/cookie.txt');
curl_setopt($ch, CURLOPT_COOKIEFILE,  dirname(__FILE__).'/cookie.txt');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, array(
  'user'=>'[email protected]',
  'password'=>'pass'
));
curl_exec($ch);
curl_close($ch);


A cookie is created in which one single line is commented out! Why, what is wrong, I do not understand.
#HttpOnly_.www.site.ru	TRUE	/	FALSE	0	PHPSESSID	8i9thdlnkjeo50dleiffigb6lh


Accordingly, the curl site does not open further (the site is available only after authorization).

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Developer, 2021-02-13
@samodum

It is necessary to study all POST / GET requests, there can be no answer without this.
For example, there may be a scripted captcha that you do not take into account, but it is displayed and taken into account in requests.

N
Newto, 2021-02-14
@Newto

It all depends on how the authorization on the site is built.
Try

CURLOPT_HTTPHEADER => array(
    'Authorization: Basic ' . base64_encode($user.':'.$password)
);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question