Advertisement
arijulianto

PHP Login with Facebook

Oct 2nd, 2014
402
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.04 KB | None | 0 0
  1. <?php
  2. include "../plugin/facebook/facebook.php";
  3.  
  4.  
  5. $appId = 'xxxxxx';
  6. $secret = 'xxxxxxxxxxxx';
  7.  
  8. $facebook = new Facebook(array(
  9.             'appId' => $appId,
  10.             'secret' => $secret
  11. ));
  12.  
  13.  
  14. //Get User ID
  15. $user = $facebook->getUser();
  16.  
  17. // Login url
  18. $loginUrl = $facebook->getLoginUrl($params = array('scope'=>'public_profile ,email','redirect_uri' => 'http://mysite.com/login.php?media=facebook&auth=1'));
  19.  
  20. if($_GET['auth'] && $_GET['code'] && $_GET['state']){
  21.   $sql = mysql_query("SELECT * from users where fbid='$user'") or die(mysql_error());
  22.   if(mysql_num_rows($sql)>0){
  23.    $user = mysql_fetch_array($sql);
  24.    if($user['blokir']=="N"){
  25.       $_SESSION['x_user'] = $user['username'];
  26.       $_SESSION['x_name'] = $user['nama'];
  27.       $_SESSION['x_level'] = $user['level'];
  28.   }}
  29.   $u = explode("?",$_SERVER['REQUEST_URI']);
  30.   echo "<script>location.href='http://mysite.com'</script>";
  31. }else{
  32.    echo "<script>location.href='$loginUrl'</script>\n<p><a href=\"$loginUrl\">Klik di sini untuk login dengan Facebook Anda</a></p>";
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement