forked from elsplatto/hcf-btw
-
Notifications
You must be signed in to change notification settings - Fork 0
/
instagram-success.php
77 lines (67 loc) · 2 KB
/
instagram-success.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php
require 'includes/site-settings.php';
require 'includes/db.php';
require 'includes/instagram.class.php';
require 'includes/instagram.config.php';
// Receive OAuth code parameter
if (isset($_GET['code']))
{
$code = $_GET['code'];
}
if (isset($_GET['call_page']))
{
$redirectPage = $_GET['call_page'];
}
if (isset($_GET['hub_challenge']))
{
$challenge = $_GET['hub_challenge'];
}
//echo '['.$redirectPage.']';
// Check whether the user has granted access
if (true === isset($code))
{
// Receive OAuth token object
$data = $instagram->getOAuthToken($code);
if(empty($data->user->username))
{
header('Location: '.$redirectPage);
//header('Location: index.php');
}
else
{
$instagram->setAccessToken($data);
session_start();
// Storing instagram user data into session
$_SESSION['userdetails']=$data;
$user=$data->user->username;
$fullname=$data->user->full_name;
$bio=$data->user->bio;
$website=$data->user->website;
$instagramID=$data->user->id;
$token=$data->access_token;
// Verify user details in USERS table
$id=mysql_query("select instagram_id from instagram_users where instagram_id='$instagramID'");
if(mysql_num_rows($id) == 0)
{
// Inserting values into USERS table
mysql_query("insert into instagram_users(username,fullname,bio,website,instagram_id,instagram_access_token) values('$user','$fullname','$bio','$website','$instagramID','$token')");
}
// Redirecting you index.php
//echo'['.$data->user->username.']<br />';
//echo'['. $_SESSION['userdetails']->user->username.']<br />';
header('Location: '.$redirectPage);
//header('Location: index.php');
}
}
else if (isset($challenge)) {
//header('Location: ' .$redirectPage .'?challenge=' .$challenge);
}
else
{
// Check whether an error occurred
if (true === isset($_GET['error']))
{
echo 'An error occurred: '.$_GET['error_description'];
}
}
?>