<?php
$app = array(
'client_id' => '',
'client_secret' => '',
'redirect_uri' => 'http://' . $_SERVER['HTTP_HOST'] . '/ИМЯ_ФАЙЛА.php'
);
if (!isset($_GET['code']))
echo '<a href="https://oauth.vk.com/authorize?client_id=' . $app['client_id'] . '&redirect_uri=' . urlencode($app['redirect_uri']) . '&response_type=code">Войти через ВКонтакте</a>';
else {
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://oauth.vk.com/access_token?client_id=' . $app['client_id'] . '&client_secret=' . $app['client_secret'] . '&code=' . $_GET['code'] . '&redirect_uri=' . urlencode($app['redirect_uri']),
CURLOPT_HEADER => false,
CURLOPT_RETURNTRANSFER => true
));
$data = json_decode(curl_exec($curl));
curl_close($curl);
if (isset($data->access_token)) {
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://api.vk.com/method/users.get?uids=' . $data->user_id . '&fields=uid,first_name,last_name,screen_name,sex,bdate,photo_big&access_token=' . $data->access_token . '&v=5.131',
CURLOPT_HEADER => false,
CURLOPT_RETURNTRANSFER => true
));
$data = json_decode(curl_exec($curl));
curl_close($curl);
if (isset($data->response[0]->id))
foreach ($data->response[0] as $key => $value)
echo $key . ': ' . $value . '<br/>';
}
}