if (isset($_GET['code'])) { $result = false; $params = array('client_id' => $client_id, 'client_secret' => $client_secret, 'code' => $_GET['code'], 'redirect_uri' => $redirect_uri); $token = json_decode(file_get_contents('https://oauth.vk.com/access_token' . '?' . urldecode(http_build_query($params))), true); if (isset($token['access_token'])) { $params = array('uids' => $token['user_id'], 'fields' => 'uid,first_name,last_name,screen_name,sex,bdate,photo_big', 'access_token' => $token['access_token']); $userInfo = json_decode(file_get_contents('https://api.vk.com/method/users.get' . '?' . urldecode(http_build_query($params))), true); if (isset($userInfo['response'][0]['uid'])) { $userInfo = $userInfo['response'][0]; $result = true; } } if ($result) { $login = formChars($userInfo['uid']); $pass = formChars($userInfo['uid']); $repass = formChars($userInfo['uid']); $id = userLogin($login, $pass, $con); if ($id == false) { newUser($login, "", $pass, $repass, "vkontakte", $userInfo['first_name'], "", $userInfo['photo_bit'], $con); } $id = userLogin($login, $pass, $con); usersLog($id, "Пользователь успешно авторизовался и вошел в сеть", $con); $_SESSION['idUser'] = $id; header("Location: ../pages/profile.php"); exit; /* echo "Социальный ID пользователя: " . $userInfo['uid'] . '<br />'; echo "Имя пользователя: " . $userInfo['first_name'] . '<br />'; echo "Ссылка на профиль пользователя: " . $userInfo['screen_name'] . '<br />'; echo "Пол пользователя: " . $userInfo['sex'] . '<br />'; echo "День Рождения: " . $userInfo['bdate'] . '<br />';
function usersLog($id, $action, $con) { $id = formChars($id); $action = formChars($action); $date = date("Y-m-d H:i:s"); mysqli_query($con, "INSERT INTO usersLog (idUser,action,date) VALUES ('" . $id . "','" . $action . "','" . $date . "')"); return true; }