Skip to content

Instantly share code, notes, and snippets.

@vovs03
Created October 28, 2018 06:08
Show Gist options
  • Save vovs03/e759676a828e9e59a0e41926629dfd97 to your computer and use it in GitHub Desktop.
Save vovs03/e759676a828e9e59a0e41926629dfd97 to your computer and use it in GitHub Desktop.
curl autologin website question

curl autologin website question

http://phpforum.su/index.php?showtopic=59662

$url = 'http://mail.ru';                        // Куда зайти
$urlTo = 'http://auth.mail.ru/cgi-bin/auth';    // Куда данные послать
$login = 'your_login';                          // Логин
$pass = 'your_pass';                            // Пароль
$domain = 'mail.ru';                            // Домен
$post = 'Login=' . $login . '&Domain=' . $domain . '&Password=' . $pass;    // POST данные

$ch = curl_init();                              // Инициализация сеанса
curl_setopt($ch, CURLOPT_URL, $url);            // Заходим на сайт
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // Приказываем вернуть страницу в переменную

$html = curl_exec($ch);                         // Забираем страницу

curl_setopt($ch, CURLOPT_URL, $urlTo);              // Куда шлем POST данные
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');  // Записываем cookie
curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookie.txt'); // Читаем cookies
curl_setopt($ch, CURLOPT_POST, true);               // Указываем метод отправки
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);        // POST данные
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);     // Говорим скрипту, чтобы он следовал за редиректами которые происходят во время авторизации

$html = curl_exec($ch); // Забираем страницу
curl_close($ch);        // Завершаем сеанс
echo $html;             // Оказываемся в вашем ящике
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment