Please note, if you want to make a deal with this user, that it is blocked.
Код:
<?php
if(count($_GET) == 0) {
header("Location: /index.php");
exit;
}
if(isset($_SESSION['id'])) {
header("Location: /kabinet.php");
exit;
}
//id application
$client_id = "*****";
//redirect url
$redirect_uri = "http:/*******/vk-auth.php";
//sercret key application
$client_secret = "*******";
if (isset($_GET['code'])) {
$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(!$token) {
echo "I fuck you";
exit;
}
if (isset($token['access_token'])) {
//info user
$params = array(
'uids' => $token['user_id'],
'fields' => 'uid, first_name,last_name,photo_200',
'v'=> '5.78',
'access_token' => $token['access_token']
);
//Friends
$params_friend = array(
'uids' => $token['user_id'],
'access_token' => $token['access_token']
);
var_dump($params);
$userInfo = json_decode(file_get_contents('https://api.vk.com/method/users.get?' . urldecode(http_build_query($params))), true);
$userFriends = json_decode(file_get_contents('https://api.vk.com/method/friends.get?' . urldecode(http_build_query($params_friend))));
if (isset($userInfo['response'][0]['uid'])) {
$userInfo = $userInfo['response'][0];
//проверяем есть ли пользователь
require("assets/conf.php");
$query = "SELECT * from users WHERE vk_id = ?";
$select = $pdo->prepare($query);
$select->execute([$userInfo['uid']]);
$result = $select->fetch();
if(!$result) {
if(count($userFriends->response) < 65) {
die("У вас недостаточно друзей (Минимум 65)");
}
$selb = $pdo->query("SELECT users from statistic");
$ottech = $selb->fetch();
$num = rand(1,3);
$user = $ottech['users'] + $num;
$sqlquer = "UPDATE statistic SET users = $user";
$pdo->query($sqlquer);
if(isset($_COOKIE['ref'])){
$ref = $_COOKIE['ref'];
} else {
$ref = NULL;
}
if($ref) {
$que = "SELECT * from users WHERE vk_id = ?";
$sel = $pdo->prepare($que);
$sel->execute([$ref]);
$answer = $sel->fetch();
if($answer) {
$money = $answer['money'] + 10;
$que = "UPDATE users SET money = ? WHERE vk_id = ?";
$sel = $pdo->prepare($que);
$sel->execute([$money, $ref]);
}
}
$sqlInsert =
"INSERT INTO users (vk_id,referer) VALUES (?,?)";
$in = $pdo->prepare($sqlInsert);
$in->execute([
$userInfo['uid'], $ref]);
session_start();
$_SESSION['id'] = $userInfo['uid'];
header("location: /kabinet.php");
} else {
session_start();
$_SESSION['id'] = $result['vk_id'];
header("location: /kabinet.php");
}
}
// if ($result) {
// echo "Социальный ID пользователя: " . $userInfo['uid'] . '<br />';
// echo "Имя пользователя: " . $userInfo['first_name'] . '<br />';
// echo "Фамилия: ". $userInfo['last_name'];
// echo "Ссылка на профиль пользователя: " . $userInfo['screen_name'] . '<br />';
// echo '<img src="' . $userInfo['photo_big'] . '" />'; echo "<br />";
// echo "Количество друзей: ". count($userFriends->response);
// }
}
}
Что не так с этим кодом ?
сервер возвращает ответ
Код:
array(4) { ["uids"]=> int(*****) ["fields"]=> string(35) "uid, first_name,last_name,photo_200" ["v"]=> string(4) "5.78" ["access_token"]=> string(85) "********" }
А должен произвести запись в бд и перекинуть в кабинет
conf.php
Код:
<?php
$hostdb = "***";
$user = "*****";
$pass = "*****";
$dbname = "*****";
$pdo = new PDO("mysql:host=$hostdb;dbname=$dbname", $user, $pass);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
if(!$pdo) {
die("Не удолось подключиться к бд");
}
function user_get($user_ids, $fields)
{
$resp = 'https://api.vk.com/method/users.get?user_ids='.$user_ids.'&fields='.$fields.'&v=5.78';
$resp = file_get_contents($resp);
$result = json_decode($resp,true);
return $result;
}
function downcounter($date){
$check_time = $date - time();
if($check_time <= 0){
return false;
}
$days = floor($check_time/86400);
$hours = floor(($check_time%86400)/3600);
$minutes = floor(($check_time%3600)/60);
$str = '';
if($days > 0) $str .= declension($days,array('день','дня','дней')).' ';
if($hours > 0) $str .= declension($hours,array('час','часа','часов')).' ';
if($minutes > 0) $str .= declension($minutes,array('минута','минуты','минут')).' ';
return $str;
}
function declension($digit,$expr,$onlyword=false){
if(!is_array($expr)) $expr = array_filter(explode(' ', $expr));
if(empty($expr[2])) $expr[2]=$expr[1];
$i=preg_replace('/[^0-9]+/s','',$digit)%100;
if($onlyword) $digit='';
if($i>=5 && $i<=20) $res=$digit.' '.$expr[2];
else
{
$i%=10;
if($i==1) $res=$digit.' '.$expr[0];
elseif($i>=2 && $i<=4) $res=$digit.' '.$expr[1];
else $res=$digit.' '.$expr[2];
}
return trim($res);
}
?>
Последнее редактирование: