-
Notifications
You must be signed in to change notification settings - Fork 3
/
fb.php
41 lines (38 loc) · 1.22 KB
/
fb.php
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
<?
require 'fb/facebook.php';
require_once "incl/function.php";
$isglobal = 1;
require_once "config.php";
$db = new db("global");
$session = new session;
// Create our Application instance (replace this with your appId and secret).
$facebook = new Facebook($config['fb']);
// Get User ID
$user = $facebook->getUser();
if ($user) {
try {
// Proceed knowing you have a logged in user who's authenticated.
$user_profile = $facebook->api('/'.$user);
} catch (FacebookApiException $e) {
error_log($e);
$user = null;
}
}
// Login or logout url will be needed depending on current user state.
if ($user) {
$logoutUrl = $facebook->getLogoutUrl();
} else {
$loginUrl = $facebook->getLoginUrl(array('scope' => 'email'));
header("Location: ".$loginUrl);
}
if(isset($user_profile['id'])) {
if($db->exist("SELECT `id` FROM `login` WHERE `fbid` = '".$user_profile['id']."'")) {
$userinfo = $db->query("SELECT `id` FROM `login` WHERE `fbid` = '".$user_profile['id']."'");
$session->create($userinfo);
header("Location: index.php");
} else { //Account muss erstellt werden
header("Location: index.php?page=register&fbid=".$user_profile['id']."&user=".$user_profile['username']."&email=".$user_profile['email']."");
exit;
}
}
?>