Вход Регистрация
Файл: vk/Auth_Vk.php
Строк: 41
<?php
class Auth_Vk {
    private 
$code,
            
$token,
            
$uid;
            
    public function 
__construct() {
        require(
'config.php');
    }
    
    public function 
set_code($code) {
        
$this->code = $code;
    }
    
    public function 
set_token($token) {
        
$this->token = $token;
    }
    
    public function 
set_uid($id) {
        
$this->uid = $id;
    }
    
    public function 
get_token() {
        if (!
$this->code) {
            exit(
'Не верный код');
        }
        
        
$query = "client_id=" . APP_ID . "&client_secret=" . APP_SECRET . "&code=" . $this->code . "&redirect_uri=" . REDIRECT_URI;
        
$result = file_get_contents(URL_ACCESS_TOKEN . "?" . $query);
        
$data = json_decode($result);

        if (!empty(
$data->access_token)) {
            
$this->set_token($data->access_token);
            
$this->set_uid($data->user_id);
            return 
true;
        }
        
$_SESSION['error'] = 'Ошибка!';
        return 
false;
    }
    
    public function 
get_user() {
        if (!
$this->token || !$this->uid) {
            exit(
'Не верный код');
        }
        
        
$query = "uids=" . $this->uid . "&fields=".USER_FIELDS."&access_token=" . $this->token;
        
$result = file_get_contents(URL_GET_USER . "?" . $query);

        
$_SESSION['user'] = json_decode($result); 
        
Auth_Vk::redirect('index.php');     
    }
    
    static public function 
redirect($url) {
        
header("Location:" . $url);
        exit;
    }
}
Онлайн: 2
Реклама