Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require_once 'autoload.php';
- require_once 'config.php';
- if ($_SESSION['page']){
- $lastpage = $_SESSION['page'];
- }else{
- $_SESSION['page'] = $_SERVER['HTTP_REFERER'];
- }
- // added in v4.0.0
- use Facebook\FacebookSession;
- use Facebook\FacebookRedirectLoginHelper;
- use Facebook\FacebookRequest;
- use Facebook\FacebookResponse;
- use Facebook\FacebookSDKException;
- use Facebook\FacebookRequestException;
- use Facebook\FacebookAuthorizationException;
- use Facebook\GraphObject;
- use Facebook\Entities\AccessToken;
- use Facebook\HttpClients\FacebookCurlHttpClient;
- use Facebook\HttpClients\FacebookHttpable;
- // init app with app id and secret
- FacebookSession::setDefaultApplication( 'removedID','removedSECRET' );
- // login helper with redirect_uri
- $helper = new FacebookRedirectLoginHelper('http://domain.com/assets/login.php' );
- try {
- $session = $helper->getSessionFromRedirect();
- } catch( FacebookRequestException $ex ) {
- // When Facebook returns an error
- } catch( Exception $ex ) {
- // When validation fails or other local issues
- }
- // see if we have a session
- if ( isset( $session ) ) {
- // graph api request for user data
- $request = new FacebookRequest( $session, 'GET', '/me?fields=id,name,email,gender');
- $response = $request->execute();
- // get response
- $graphObject = $response->getGraphObject();
- $fbid = $graphObject->getProperty('id'); // To Get Facebook ID
- $fbfullname = $graphObject->getProperty('name'); // To Get Facebook full name
- $femail = $graphObject->getProperty('email'); // To Get Facebook email
- $fbgender = $graphObject->getProperty('gender'); // To Get Facebook gender
- $token = $session->getToken();
- /* ---- Session Variables -----*/
- $_SESSION['FBID'] = $fbid;
- $_SESSION['FULLNAME'] = $fbfullname;
- $_SESSION['EMAIL'] = $femail;
- $id = $_SESSION['FBID'];
- $name = $_SESSION['FULLNAME'];
- /* ---- Insert in Database -----*/
- $query = mysqli_query($db, 'SELECT * FROM users WHERE fbid="'.$id.'"');
- $checkacc = mysqli_num_rows($query);
- if($checkacc == "0"){
- $db->query("INSERT INTO users (`fbid`, `ime`, `token`, `email`, `aktivacija`, `gender`) VALUES ('$fbid', '$fbfullname', '$token', '$femail', 0, '$fbgender')");
- }
- $db->query("UPDATE users SET token='".$token."' WHERE fbid='".$id."'");
- copy('https://graph.facebook.com/'.$id.'/picture?width=150&height=150', '/home/sandip/www/slike/'.$id.'.jpeg');
- copy('https://graph.facebook.com/'.$id.'/picture?width=100&height=100', '/home/sandip/www/slike/small/'.$id.'.jpeg');
- copy('https://graph.facebook.com/'.$id.'/picture?width=200&height=200', '/home/sandip/www/slike/big/'.$id.'.jpeg');
- /* ---- header location after session ----*/
- header("Location: ".$lastpage);
- } else {
- $loginUrl = $helper->getLoginUrl();
- header("Location: ".$loginUrl);
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement