May
28

Facebook Connect Logout.

Tags:  Facebook Connect Logout 

Facebook Connect Logout
I have been getting a lot of users looking for either the Facebook Connect logout button or the way it is implemented. The Facebook Connect logout function is very easy to set up. All all you need to do is make sure you have included the following code in your page.

Note: I wont touch on basic Facebook Connect setup here, I assume you are already able to login successfully. If not, check out my post on setting up FBConnect from scratch.

HTML:
<a href = \"#\" onclick = \"FB.Connect.logout(function() { FBCLogout(); }); return(false);\">
<img id = \"fb_logout_image\" src = \"http://static.ak.fbcdn.net/images/fbconnect/logout-buttons/logout_small.gif\" alt = \"Connect\" />
</a>

JavaScript:
<script type="text/javascript">
function FBCLogout() {
FB.XFBML.Host.parseDomTree();
}
</script>


It's just that simple. The logout button is loaded directly from Facebook so no need to worry about that, and the anchor tag calls the FCBLogout() function I made to parse the DOM tree to update the Facebook authentication status.

I also like setting Facebook Connect logout this way because it allows you to add AJAX right in the JavaScript function above the FB code when you are ready to add it.

I hope this helps.

Comments

hi how to show the facebook login button and when click on it for login after login this login button must be hide and replece it logout button. please tell me code.


waiting
thanks advance

ashfaq about 1 month ago

i have a site that allows people to have accounts that are not linked to facebook accounts. we integrated facebook connect as an alternate login system.

as such when we log people in via either method we set a php session variable.

on log out we set up a php script to clear & destroy this session.

I'm having trouble getting the log out method here to redirect to the php script so the php sessions can be destroyed.


If i use this method the user is logged out of facebook but not our site. If i call the php script the user is logged out of our site but not facebook.

Any help would be appreciated.

jeff about 16 days ago

Do you know AJAX? that would solve your problem.

I have set the above example up in such a way that the FBClogout(); function can trigger an AJAX call to destroy your session. It is important to note that the FBClogout(); function is a function that I have created and not one included in the Facebook API.

If you don't know AJAX... get jQuery on your site. Look at the $.ajax() function. If you still can't get it, come back and post.

Marcus about 16 days ago

I was initially just trying to do a page redirect to the php page inside FBClogout(). That didn't work (not entirely sure why). I don't really know ajax / jquery so thats why i was just trying to redirect to the page.

I got the Ajax call going now though, it wasn't as painful as i thought it would be. Actually it was pretty easy considering it was my first atempt at the whole ajax thing.

Now it all works as it should.

Thanks for the advice.

Jeff about 16 days ago

Leave a Comment

Name
Email (optional)
Website (optional)
...or login using Facebook to bypass these fields.
Messageusable tags: <b> <i>
Robot?
Loading tweets...
Site designed, developed and coded by Marc Whitbread and Whitbread Design ©2010