Lucky2710 Posted August 6, 2011 Share Posted August 6, 2011 I'm using facebook connect as an alternative login method for my users on my website. (ex forget your credentials to my website use your facebook credentials) Ive got the facebook login working and ive got it working in conjunction with my login system. In facebooks terms and conditions you have to include a facebook logoff if you have a facebook login on your website. I have managed to get it to logoff on a <button></button> But thats the oinly way i can get it to work! I need it to run automatically on my logout script page. My current Logout.php (NOTE: Only kills the session and logs out of my php login script THE JAVASCRIPT DOES NOT WORK CORRECTLY AND LOGOUT OF FACEBOOK LIKE ITS SUPPOSED TO) <?php include_once('framework/checkuserlog.php'); ?> <div id="fb-root"></div> <script> window.fbAsyncInit = function() { FB.init({appId: 'APP_ID_HERE', status: true, cookie: true, xfbml: true}); FB.logout(function(response) {}); }; (function() { var e = document.createElement('script'); e.async = true; e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js'; document.getElementById('fb-root').appendChild(e); }()); </script> <?php session_destroy(); ?> <script> location.href='index.php'; </script> Working Script To Logout on a <button> <div id="fb-root"></div> <script type="text/javascript"> var button; var userInfo; window.fbAsyncInit = function() { FB.init({ appId: 'APP_ID_HERE', status: true, cookie: true, xfbml: true, oauth: true}); showLoader(true); function updateButton(response) { button = document.getElementById('fb-auth'); userInfo = document.getElementById('user-info'); if (response.authResponse) { //user is already logged in and connected FB.api('/me', function(info) { login(response, info); }); button.onclick = function() { FB.logout(function(response) { logout(response); }); }; } else { //user is not connected to your app or logged out button.innerHTML = 'Login with Facebook'; button.onclick = function() { showLoader(true); FB.login(function(response) { if (response.authResponse) { FB.api('/me', function(info) { login(response, info); }); } else { //user cancelled login or did not grant authorization showLoader(false); } }, {scope:'email,user_birthday'}); } } } // run once with current status and whenever the status changes FB.getLoginStatus(updateButton); FB.Event.subscribe('auth.statusChange', updateButton); }; (function() { var e = document.createElement('script'); e.async = true; e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js'; document.getElementById('fb-root').appendChild(e); }()); function login(response, info){ if (response.authResponse) { var accessToken = response.authResponse.accessToken; userid = response.authResponse.userID; userInfo.innerHTML = ''; button.innerHTML = 'Logout'; showLoader(false); document.getElementById('other').style.display = "block"; } } function logout(response){ userInfo.innerHTML = ""; document.getElementById('debug').innerHTML = ""; document.getElementById('other').style.display = "none"; showLoader(false); } function showLoader(status){ if (status) document.getElementById('loader').style.display = 'block'; else document.getElementById('loader').style.display = 'none'; } </script> <button id="fb-auth">Login with Facebook</button> <div id="loader" style="display:none"></div> <div id="user-info"></div> <div id="debug"></div> <div id="other" style="display:none"></div> Stuff that might help with a solution ------------------------------------------------ All Facebook connect code is using facebooks javascript sdk loaded Asynchronously All my traditional custom built login script is built in php and is almost 100% mysql database driven Server:Apache/2.0.52 (Red Hat) MySQL Server: Version 5.1.42 Quote Link to comment Share on other sites More sharing options...
ZulfadlyAshBurn Posted August 6, 2011 Share Posted August 6, 2011 use php sdk instead. its much easier. i used php sdk for my app. Quote Link to comment Share on other sites More sharing options...
Lucky2710 Posted August 7, 2011 Author Share Posted August 7, 2011 I figured it out i ditched my first idea when i figured out people were doing this on a link with auto-redirect. Step 1: Initialize the javascript sdk Step 2: Put a link to logout Code for link -------------------- <a href="#" onclick="javascript:FB.logout(function() { window.location='PUT YOUR REDIRECT URL HERE' }); return false;">Logout</a> NOTE: I am running the facebook login as a parrallel login to my websites current php login system so my redirect url went to a page that runs (almost in the background) to destroy my php session and then again auto redirects back to my index page. By doing it this way in the users ONE click it logs them completely out of both facebook and my website Code for my redirect (aka. my website log out) -------------------------------------------------------------- <?php include_once('framework/checkuserlog.php'); ?> <script> function killSession(){ var code = "<?php session_destroy();?>"; return (code); } killSession(); </script> <script> location.href='index.php'; </script> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.