<?php
function post($url = null, $params = null) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
if(isset($params['params'])) {
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $params['params']);
}
if(isset($params['headers'])) {
curl_setopt($ch, CURLOPT_HTTPHEADER, $params['headers']);
}
if(isset($params['cookies'])) {
curl_setopt($ch, CURLOPT_COOKIE, $params['cookies']);
}
$result = curl_exec($ch);
$result_explode = explode("\r\n\r\n", $result);
$headers = ((isset($result_explode[0])) ? $result_explode[0]."\r\n" : '').''.((isset($result_explode[1])) ? $result_explode[1] : '');
$content = $result_explode[count($result_explode) - 1];
preg_match_all('|Set-Cookie: (.*);|U', $headers, $parse_cookies);
$cookies = implode(';', $parse_cookies[1]);
curl_close($ch);
return array('headers' => $headers, 'cookies' => $cookies, 'content' => $content);
}
function ref($params = null){
// Поиск ссылки в строке "Location:"
preg_match('/Location\: (.*)/', $params, $result);
// Удаление пробелов в начале и конце
$result = trim($result[1]);
// Результат
return $result;
}
function login($email = null, $pass = null){
$post_vk = post('https://oauth.vk.com/authorize?v=5.62&client_id=3280318&scope=friends,schools,email&display=page&response_type=code&redirect_uri='.urlencode('https://ulogin.ru/auth.php?name=vkontakte'));
preg_match('/name=\"ip_h\" value=\"(.*?)\"/s', $post_vk['content'], $ip_h);
preg_match('/name=\"lg_h\" value=\"(.*?)\"/s', $post_vk['content'], $lg_h);
preg_match('/name="to" value="(.*?)\"/s', $post_vk['content'], $to_);
// Запрос на авторизацию
$post_login = post('https://login.vk.com/?act=login&soft=1', array(
'params' => 'ip_h='.$ip_h[1].'&lg_h='.$lg_h[1].'&_origin='.urlencode('https://oauth.vk.com').'&to='.$to_[1].'&expire=0&email='.$email.'&pass='.$pass,
'cookies' => $post_vk['cookies'])
);
$post_hash = post(ref($post_login['headers']), array(
'cookies' => $post_login['cookies'])
);
echo $post_hash['headers'];
preg_match('/Location\: (.*)/', $post_hash['headers'], $url_code);
$post_code = post(trim($url_code[1]), array(
'cookies' => $post_hash['cookies'])
); //
echo $post_code['headers']; //<= <b>ТУТ выходит ошибка</b>
}
login($mail,$password);
?>
echo $post_code['headers']; //<=
ТУТ выходит ошибка в этом месте должен отображаться переход по ссылки полученой выше, но выдает ссылку
Location: https://oauth.vk.com/error?err=2, как будто куки не передаются и авторизация слетает. Что не нравится, почему не получает ссылку для редиректа?