Файл: auth/vk/index.php
Строк: 20
<?php
define("DBHOST", "localhost");
define("DBUSER", "miledi");
define("DBNAME", "trance24");
define("DBPASS", "112233xx");
$db = mysqli_connect(DBHOST, DBUSER, DBPASS, DBNAME) or die("Error " . mysqli_error($db));
mysqli_set_charset($db, "utf8");
session_start();
echo '<a href="auth.php">Авторизоваться</a><br />';
if (!empty($_SESSION['user'])) {
$data = (array)$_SESSION['user']->response[0];
/*echo '<b>Полученные данные:</b><br />'
. 'ID вконтакте: ' . $data['uid'] . '<br />'
. 'Имя: ' . $data['first_name'] . '<br />'
. 'Фамилия: ' . $data['last_name'] . '<br />'
. 'Пол: ' . ($data['sex'] === 2 ? 'Мужской' : 'Женский') . '<br />'
. 'Дата рождения: ' . $data['bdate'] . '<br />'
. 'Фото: <img src="'.$data['photo_big'].'" alt=""/><br />';*/
$query = "SELECT * FROM users WHERE social_type = 'vk' && social_id = '".$data['uid']."'";
$result = mysqli_query($db, $query);
$row = mysqli_fetch_array($result);
if (empty($row)) {
$query = "INSERT INTO users
(first_name, last_name, sex, bdate, social_id, social_type, level, date_rec)
VALUES
('".$data['first_name']."', '".$data['last_name']."', '".$data['sex']."', '".$data['bdate']."', '".$data['uid']."', 'vk', '0', NOW())";
mysqli_query($db, $query);
$last_id = mysqli_insert_id($db);
if (!empty($data['photo_big'])) {
copy($data['photo_big'], '../../users_photos/' . $last_id . '.jpg');
}
$_SESSION['user_id'] = $last_id;
} else {
$_SESSION['user_id'] = $row['id'];
}
unset($_SESSION['user']);
header("Location: http://trance24.ru");
exit;
}