login-vkontakte.php
1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
require 'config/functions.php';
function curl_get($url, array $get = NULL, array $options = array())
{
$defaults = array(
CURLOPT_URL => $url. (strpos($url, '?') === FALSE ? '?' : ''). http_build_query($get),
CURLOPT_HEADER => 0,
CURLOPT_RETURNTRANSFER => TRUE,
CURLOPT_TIMEOUT => 4
);
$ch = curl_init();
curl_setopt_array($ch, ($options + $defaults));
if( ! $result = curl_exec($ch))
{
trigger_error(curl_error($ch));
}
curl_close($ch);
return $result;
}
$data = @curl_get("https://oauth.vk.com/access_token",array('client_id'=>'3079859','client_secret'=>'l1UuAupvdiL8q8R6J7v3','code'=>trim($_GET['code'])));
$datas = @json_decode(@$data);
if(trim($datas->user_id)!="")
$id_a = @$db->super_query("SELECT * FROM `zlo_users` WHERE `UID`='".$datas->user_id."' LIMIT 1;");
//echo "1";
if(!@$id_a['id'] && trim($datas->user_id)!=''){
$dataf = curl_get("https://api.vk.com/method/getProfiles",array('uid'=>$datas->user_id,'access_token'=>$datas->access_token));
$dataf = json_decode($dataf);
$first_name = iconv("UTF-8","cp1251",$dataf->response[0]->first_name);
$last_name = iconv("UTF-8","cp1251",$dataf->response[0]->last_name);
$db->query("INSERT INTO `zlo_users` (`username`,`group`,`registered`,`mailing`,`UID`) VALUES ('".$first_name." ".$last_name."',2,'".date("Y-m-d H:i:s")."',1,'".trim($datas->user_id)."');");
session_start();
if(trim($first_name)!="" && trim($last_name)!=""){
$_SESSION['user'] = array('id'=>$db->insert_id(),'login'=>$first_name." ".$last_name);
@header("Location: /account/info/");
} else @header("Location: /");
}else{
if(@$id_a['username']!=""){
$_SESSION['user'] = array('id'=>@$id_a['id'],'login'=>@$id_a['username']);
@header("Location: /account/info/");
}else @header("Location: /");
}
?>