Guest User

Untitled

a guest
Apr 29th, 2012
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.14 KB | None | 0 0
  1. Facebook-connect : Can't logout using PHP SDK JS SDK
  2. <?
  3. //uses the PHP SDK. Download from https://github.com/facebook/php-sdk
  4. require 'src/facebook.php';
  5. $facebook = new Facebook(array(
  6. 'appId' => 'ddddd',
  7. 'secret' => 'ddddddddddddddd',
  8. ));
  9.  
  10. $userId = $facebook->getUser();
  11.  
  12. ?>
  13. <?php if ($userId) {
  14. $userInfo = $facebook->api('/' + $userId);
  15. $params = array('next' => 'http://www.nofrenchtouch.com/include/logout.php');
  16. $logout = $facebook->getlogoutURL($params);?>
  17.  
  18. <span class="facebook-in">Bienvenue <?= $userInfo['name']?> - <a href="#" onClick="logoutUser(); return false;" class="facebook-bt"> Se déconnecter</a>
  19. </span>
  20. <?php } else { ?>
  21. <div id="fb-root"></div>
  22. <a href="#" class="facebook-bt" onClick="loginUser(); return false;">Se connecter avec Facebook</a>
  23. <?php } ?>
  24.  
  25.  
  26. <script>
  27. window.fbAsyncInit = function() {
  28. FB.init({
  29. appId: '<?php echo $facebook->getAppID() ?>',
  30. cookie: true,
  31. xfbml: true,
  32. oauth: true
  33. });
  34. FB.Event.subscribe('auth.login', function(response) {
  35. window.location.reload();
  36. });
  37. FB.Event.subscribe('auth.logout', function(response) {
  38. window.location.reload();
  39. });
  40. };
  41. (function(d){
  42. var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
  43. js = d.createElement('script'); js.id = id; js.async = true;
  44. js.src = "//connect.facebook.net/fr_FR/all.js";
  45. d.getElementsByTagName('head')[0].appendChild(js);
  46. }(document));
  47.  
  48. function loginUser() {
  49. FB.login(
  50. function(response) {
  51. getStatus(); //This is a call to a different function...
  52. },
  53. {scope:'email,publish_stream, user_birthday, friends_birthday'}
  54. );
  55.  
  56. function logoutUser() {
  57. FB.logout(
  58. function(response) {
  59. }
  60. );
  61. }
  62. </script>
  63.  
  64. <a href="javascript:FB.logout();void(0)">Log Out</a>
  65.  
  66. function logoutUser() {
  67. FB.logout(
  68. function(response) {
  69. //Pass control to function in php where you can destroy your session and cookies.
  70. // windows.location=PHP function
  71. }
  72. );
Advertisement
Add Comment
Please, Sign In to add comment