Advertisement
Guest User

Untitled

a guest
Aug 27th, 2013
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.20 KB | None | 0 0
  1.  
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4. <head>
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  6. <title>Login with Facebook</title>
  7. <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js" type="text/javascript"></script>
  8. <script type="text/javascript" src="js/oauthpopup.js"></script>
  9. <script type="text/javascript">
  10. $(document).ready(function(){
  11. $('#facebook').click(function(e){
  12. $.oauthpopup({
  13. path: 'login.php',
  14. width:600,
  15. height:300,
  16. callback: function(){
  17. window.location.reload();
  18. }
  19. });
  20. e.preventDefault();
  21. });
  22. });
  23.  
  24.  
  25. </script>
  26. </head>
  27.  
  28. <body>
  29. <?php
  30. session_start();
  31. if(!isset($_SESSION['User']) && empty($_SESSION['User'])) { ?>
  32. <img src="images/facebook.png" id="facebook" style="cursor:pointer;float:left;margin-left:550px;" />
  33. <?php } else{
  34.  
  35. echo '<img src="https://graph.facebook.com/'. $_SESSION['User']['id'] .'/picture" width="30" height="30"/><div>'.$_SESSION['User']['name'].'</div>';
  36. echo '<a href="'.$_SESSION['logout'].'">Logout</a>';
  37.  
  38.  
  39.  
  40.  
  41. }
  42. ?>
  43.  
  44. </body>
  45. </html>
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57. //login.php
  58.  
  59.  
  60.  
  61. require 'config.php';
  62. require 'lib/facebook/facebook.php';
  63.  
  64. $facebook = new Facebook(array(
  65. 'appId' => $appID,
  66. 'secret' => $appSecret,
  67. ));
  68. //get the user facebook id
  69. $user = $facebook->getUser();
  70.  
  71. if($user){
  72.  
  73. try{
  74. //get the facebook user profile data
  75. $user_profile = $facebook->api('/me');
  76. $params = array('next' => $base_url.'logout.php');
  77. //logout url
  78. $logout =$facebook->getLogoutUrl($params);
  79. $_SESSION['User']=$user_profile;
  80. $_SESSION['logout']=$logout;
  81. }catch(FacebookApiException $e){
  82. error_log($e);
  83. $user = NULL;
  84. }
  85. }
  86.  
  87. if(empty($user)){
  88. //login url
  89. $loginurl = $facebook->getLoginUrl(array(
  90. 'scope' => 'email,read_stream, publish_stream, user_birthday, user_location, user_work_history, user_hometown, user_photos',
  91. 'redirect_uri' => 'http://www.museartgallery.in/facebook/login.php',
  92. 'display'=>'popup'
  93. ));
  94.  
  95.  
  96. header('Location: '.$loginurl);
  97.  
  98. }
  99.  
  100.  
  101.  
  102.  
  103.  
  104. ?>
  105. <!-- after authentication close the popup -->
  106. <script type="text/javascript">
  107.  
  108. window.close();
  109.  
  110. </script>
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122. //oauthpopup javascript function
  123.  
  124.  
  125.  
  126. (function (jQuery) {
  127. jQuery.oauthpopup = function (options) {
  128. options.windowName = options.windowName || 'ConnectWithOAuth';
  129. options.windowOptions = options.windowOptions || 'location=0,status=0,width='+options.width+',height='+options.height+',scrollbars=1';
  130. options.callback = options.callback || function () {
  131. window.location.reload();
  132. };
  133. var that = this;
  134. that._oauthWindow = window.open(options.path, options.windowName, options.windowOptions);
  135. that._oauthInterval = window.setInterval(function () {
  136. if (that._oauthWindow.closed) {
  137. window.clearInterval(that._oauthInterval);
  138. options.callback();
  139. }
  140. }, 1000);
  141. };
  142. })(jQuery);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement