Advertisement
Guest User

Untitled

a guest
Jul 6th, 2016
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.07 KB | None | 0 0
  1.     <?php
  2.     require_once 'autoload.php';
  3.     require_once 'config.php';
  4.     if ($_SESSION['page']){
  5.     $lastpage = $_SESSION['page'];
  6.     }else{
  7.     $_SESSION['page'] = $_SERVER['HTTP_REFERER'];
  8.     }
  9.     // added in v4.0.0
  10.     use Facebook\FacebookSession;
  11.     use Facebook\FacebookRedirectLoginHelper;
  12.     use Facebook\FacebookRequest;
  13.     use Facebook\FacebookResponse;
  14.     use Facebook\FacebookSDKException;
  15.     use Facebook\FacebookRequestException;
  16.     use Facebook\FacebookAuthorizationException;
  17.     use Facebook\GraphObject;
  18.     use Facebook\Entities\AccessToken;
  19.     use Facebook\HttpClients\FacebookCurlHttpClient;
  20.     use Facebook\HttpClients\FacebookHttpable;
  21.     // init app with app id and secret
  22.     FacebookSession::setDefaultApplication( 'removedID','removedSECRET' );
  23.     // login helper with redirect_uri
  24.     $helper = new FacebookRedirectLoginHelper('http://domain.com/assets/login.php' );
  25.     try {
  26.       $session = $helper->getSessionFromRedirect();
  27.     } catch( FacebookRequestException $ex ) {
  28.       // When Facebook returns an error
  29.     } catch( Exception $ex ) {
  30.       // When validation fails or other local issues
  31.     }
  32.     // see if we have a session
  33.     if ( isset( $session ) ) {
  34.       // graph api request for user data
  35.       $request = new FacebookRequest( $session, 'GET', '/me?fields=id,name,email,gender');
  36.       $response = $request->execute();
  37.       // get response
  38.       $graphObject = $response->getGraphObject();
  39.             $fbid = $graphObject->getProperty('id');              // To Get Facebook ID
  40.             $fbfullname = $graphObject->getProperty('name'); // To Get Facebook full name
  41.             $femail = $graphObject->getProperty('email');    // To Get Facebook email
  42.             $fbgender = $graphObject->getProperty('gender'); // To Get Facebook gender
  43.             $token = $session->getToken();
  44.         /* ---- Session Variables -----*/
  45.             $_SESSION['FBID'] = $fbid;          
  46.             $_SESSION['FULLNAME'] = $fbfullname;
  47.             $_SESSION['EMAIL'] =  $femail;
  48.             $id = $_SESSION['FBID'];
  49.             $name = $_SESSION['FULLNAME'];
  50.            
  51.    
  52.         /* ---- Insert in Database -----*/
  53.         $query = mysqli_query($db, 'SELECT * FROM users WHERE fbid="'.$id.'"');
  54.         $checkacc = mysqli_num_rows($query);
  55.         if($checkacc == "0"){
  56.         $db->query("INSERT INTO users (`fbid`, `ime`, `token`, `email`, `aktivacija`, `gender`) VALUES ('$fbid', '$fbfullname', '$token', '$femail', 0, '$fbgender')");
  57.     }
  58.     $db->query("UPDATE users SET token='".$token."' WHERE fbid='".$id."'");
  59.     copy('https://graph.facebook.com/'.$id.'/picture?width=150&height=150', '/home/sandip/www/slike/'.$id.'.jpeg');
  60.     copy('https://graph.facebook.com/'.$id.'/picture?width=100&height=100', '/home/sandip/www/slike/small/'.$id.'.jpeg');
  61.     copy('https://graph.facebook.com/'.$id.'/picture?width=200&height=200', '/home/sandip/www/slike/big/'.$id.'.jpeg');
  62.            
  63.     /* ---- header location after session ----*/
  64.     header("Location: ".$lastpage);
  65.     } else {
  66.       $loginUrl = $helper->getLoginUrl();
  67.      header("Location: ".$loginUrl);
  68.     }
  69.     ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement