-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathcallback.php
More file actions
44 lines (32 loc) · 1.33 KB
/
callback.php
File metadata and controls
44 lines (32 loc) · 1.33 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
<?php
session_start();
$app_id = "509011619175617";
$app_secret = "226491c9633bf31817077cfde437fe0d";
$redirect_uri = urlencode("http://localhost/fblogin/callback.php");
// Get code value
$code = $_GET['code'];
// Get access token info
$facebook_access_token_uri = "https://graph.facebook.com/v2.8/oauth/access_token?client_id=$app_id&redirect_uri=$redirect_uri&client_secret=$app_secret&code=$code";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $facebook_access_token_uri);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
$response = curl_exec($ch);
curl_close($ch);
// Get access token
$aResponse = json_decode($response);
$access_token = $aResponse->access_token;
// Get user infomation
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://graph.facebook.com/me?access_token=$access_token");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
$response = curl_exec($ch);
curl_close($ch);
$user = json_decode($response);
//print_r($user);
// Log user in
$_SESSION['user_login'] = true;
$_SESSION['user_name'] = $user->name;
echo "Wellcome ". $user->name ."!";
?>