J
J
justyork2013-12-11 08:04:55
PHP
justyork, 2013-12-11 08:04:55

Login via curl with a redirect to the page

Hello everyone, I need to send 120 combinations to the form very quickly, it will take some time manually, so I want to try to implement this using curl:

$email = [email protected]';
$pass = '123'; 
$login_url = 'http://site.ru/login';
$pin_url = 'http://site.ru/promo';
$agent = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3';
$referer = 'http://site.ru/';
$data = array('name' => $email, 'pass' => $pass, 'send' => 'Войти'); 


// вход в систему
// имя хоста, куда будем заходить 
// инициализация cURL
$ch = curl_init($login_url);
// получать заголовки
curl_setopt ($ch, CURLOPT_HEADER, 1); 
// если ведется проверка HTTP User-agent, то передаем один из возможных допустимых вариантов:
curl_setopt ($ch, CURLOPT_USERAGENT, $agent);
// елси проверятся откуда пришел пользователь, то указываем допустимый заголовок HTTP Referer:
curl_setopt ($ch, CURLOPT_REFERER, $referer);
// использовать метод POST
curl_setopt ($ch, CURLOPT_POST, 1);
// сохранять информацию Cookie в файл, чтобы потом можно было ее использовать
curl_setopt ($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
// передаем поля формы
curl_setopt ($ch, CURLOPT_POSTFIELDS, $data);
// возвращать результат работы
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
// не проверять SSL сертификат
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0);
// не проверять Host SSL сертификата
curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);
// это необходимо, чтобы cURL не высылал заголовок на ожидание
curl_setopt ($ch, CURLOPT_HTTPHEADER, array('Expect:'));
// выполнить запрос
curl_exec ($ch);
// получить результат работы
$result = curl_multi_getcontent ($ch);
// вывести результат
echo "\n".'Login OK'."\n".'[result ===8<===>'."\n".$result."\n".'<===>8=== result]'."\n";
// закрыть сессию работы с cURL
curl_close ($ch);

Everything seems to be logged in, now I need to go to the $pin_url page and go through the combinations there.
As I understand it, if I have created a cookie file, it will no longer be necessary to log in with each new attempt, if I'm wrong, correct me.
Actually questions:
1. How to go to the $pin_url page and start doing the search there?
It is possible to simply create a new session in the same session and simply navigate to a new page.
2. When iterating over combinations, so as not to calculate, I think it is necessary to set some kind of timeout?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
C
ChemAli, 2013-12-11
@justyork

0. No need to log in. Cookies should pick up themselves if you use the same options for subsequent requests (with the above cookie).
1. Make another curl_exec with $pin_url. You can not go, from once to make requests where necessary.
2. If you know what they are calculating or you are afraid that they will be calculated, bet. The easiest way is to loop over sleep(rand(15)).

A
Alexey Sundukov, 2013-12-11
@alekciy

If I remember correctly, CURLOPT_COOKIEJAR just writes session cookies to the file, but doesn't read them. Whatever reads at startup, you also need to use CURLOPT_COOKIEFILE.
2. The actions of a logged in user are logged in normal systems. Therefore, it is elementary to calculate. So it's easy to calculate, another question, but the admin needs it ... Therefore, if the goal is simply not to be banned, then timeouts will help not to shine much.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question