Log out of BOTH Wordpress & Facebook
So I've successfully integrated Facebook into my Wordpress site. I've also linked together the accounts. However, the way the site works is that you're either logged into the site via the
- Wordpress Account
- Facebook Account or
- Wordpress & Facebook
I know how to log out of Facebook and I know how to log out of Wordpress, but the two methods are using Javascript 开发者_开发百科and PHP respectively.
How would I, with one logout link, use both the PHP and Javascript logout methods?
I solved this issue by using FB.Connect.logoutAndRedirect()
<a href="#" onclick="FB.Connect.logoutAndRedirect('/fb_logout.php')">Sign out</a>
and in fb_logout.php I used: session_destroy();
like:
<?php
session_destroy();
header('Location: http://yoursite.com');
Which seems to work pretty well.
I would use Ajax. You can call the javascript function and a php script. If you have no idea how ajax works a really easy way to do is using jQuery.post.
精彩评论