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()
Sign out
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.
Related
Right now I'm trying to develop a simple website to demo three kinds of logins: Facebook, Google, and Twitter.
I have gotten both Facebook and Twitter to use PHP Sessions to hold user data so I can reference them on any page (such as showing their name, avatar.)
The site I'm making will only use login to store their basic profile information such as id, name, and email simply as a login feature, it is not necessary to use any higher level features.
However, I can't get Google sign-in to dump its contents into a session, Google insists on using a callback and catching the callback through Javascript functions on the page.
Google doc help for this: https://developers.google.com/+/web/signin/add-button
I'm not really familiar with this, and not sure how to reference a user's data page-to-page without writing a bunch of javascript catch functions, and javascript can't set PHP sessions. Plus, I want to make the three somewhat uniform, so whether they are signed into Twitter, Facebook, or Google, I can just write in PHP
if (isset($_SESSION['USERID']))
{show their info no matter what login because they set the same session fields}
And everything would be happy.
So I would like to know if I can just inject Google Login info into PHP sessions and how I'd go about doing that.
============
A trailing question I have is that I've been scouring help and tutorials for Oauth login for days, and have not really arrived at a better understanding of how to do Oauth in the way that I would just understand and write it. It seems way too complicated and specific to each service to write freehand. And most documentation is an ocean of oh god what are they even talking about. So if someone could trigger my understanding in dumb people words that would be great.
I worked around this problem, my problem and resources in regards to jQuery sign-in can be found here:
Google signin callback - get name and email
Reflection on PHP Versus JQuery
Although Google has an API for PHP, when I found it it looked old and deprecated, with little to no help/documentation. Since I was new to Google's specific login flow and I was intent on basic web language solutions (they are rather dedicated to javascript/jQuery) I followed their jQuery sign-in documentation.
Since all my other login options use PHP it was a bother to make so many exceptions for jQuery.
But, what you can do is leave the callback method in the header on your pages. On login, Google verifies the login info and bounces you back to page, you can sweep the user to the right page in the callback, and you can also use AJAX to inject login information into the database.
The good thing about the jQuery signin is you don't have to keep track of PHP sessions and variables. The bad part is it feels a bit ungainly and inconvenient compared to just talking to the server with PHP.
If interested, see workaround link above.
if ($gClient->getAccessToken()) {
$userProfile = $google_oauthV2->userinfo->get();
//DB Insert
$gUser = new Users();
$gUser->checkUser('google',$userProfile['id'],$userProfile['given_name'],$userProfile['family_name'],$userProfile['email'],$userProfile['gender'],$userProfile['locale'],$userProfile['link'],$userProfile['picture']);
$_SESSION['google_data'] = $userProfile; // Storing Google User Data in Session
var_dump($_SESSION['google_data']);
header("location: account.php");
$_SESSION['token'] = $gClient->getAccessToken();
} else {
$authUrl = $gClient->createAuthUrl();
}
I am using social-engine as Social-networking website and at same time we are having another website done in php CodeIngiter MVC. Now we want to integrate Social-engine with our website. We are using Social-engine DB only for our php website.
When we log into our website it should be automatically logged into Social-engine also. I don't know where to start from? Is there anyway to do it?
Probably you should create custom login action (default login action is in application/modules/User/controllers/AuthController.php) and launch it using AJAX, but this way is not too good because you might get unpredictable problems with session or something else.
Better way is to create login action which will be launched by user. User will click button (like facebook or twitter login buttons) and launch custom login action using data from your php website, where he is already logged in.
I will suggest you to create some API for the socialengine login and also in your php website. That way , it shall help you.
For, our mobile native application for one client, We used that approach and its working fine.
We have around 10 websites. I have been asked to create a functionality similar to Login using Facebook which now a days all websites are using, so that we do not need to register with them. We can use facebook credantials.
So out of our 10 websites we have 1 main website e.g. called abc.com(e-commerece website running on MAGENTO) . I want to put a button on other 9 websites login page called login using abc.com
how could I do that. I have checked on OAuth and MAGENTO's REST OAuth. Because I'm not that experienced so would like to have some ideas or anything else you have used. What would be the right way of doing that?
Use the below extension to login through Facebook
http://www.magentocommerce.com/magento-connect/facebookfreebelvg-4448.html
openID suggested by David in comments
I'm trying to do something similar to the login/registration flow described on this page but via php only.
http://developers.facebook.com/docs/plugins/registration/
What I want to do is display a register link if a user is logged in to facebook but not registered with my site, and a login link if they're not logged in to facebook, however I want to do this all on my side in php, and not using the fb:login-button widget. Is this possible?
I have the login url working, i just want to change the name of the button based on the users status.
You can't do it without loading the javascript lib. If you load nothing from Facebook on the client, then there is no way to do cross domain communication (security). Which means there is no way to tell who the user is, much less if they are logged into Facebook. By loading the javascript API on the client, the javascript code can check for a Facebook cookie and determine who they are and whether they are logged into Facebook or not.
Check through javascript and do a page reload if need be. Better yet, just use css to show/hide what you want.
http://developers.facebook.com/docs/reference/javascript/FB.getLoginStatus/
Yes, it is possible. Here's a tutorial:
Tutorial,
Example tutorial
We have a Flash site that integrates heavily with Facebook. When users sign up we get them to allow a Facebook app that ties into the site. This is done through the AS3 Facebook API library from Adobe.
When users have done this, they should then be able to sign up, submitting some personal details and so on. The Flash sends this request to our PHP which then checks to see if the user is actually logged into Facebook, and has allowed our app.
The problem we're having is that when a user goes to do this, the PHP facebook library says that the user is not logged in. If we then refresh the page and try signing up again, everything works fine.
I'd imagine it's a cookie thing, but we're really banging our head against a wall here and can't figure out why it's not working.
Cheers,
Mark.
Are you using OAuth (good example here by chirs coenraets)
Regardless, you may need to use a flash php/js proxy (php i presume since thats what your using) to deal with any crossdomain policy issues.