I have just implemented Facebook Authentication on my website using Facebook JavaScript.
If user logged on facebook from my website for the first time and then it need to insert data into users table (mysql) – maybe a field called fb_userid and email?
I have read the Documentation on JavaScript SDK that I can get Facebook User ID but how do I pass that into PHP so I can insert into users table?
Facebook Javascript look like this:
<script>
window.fbAsyncInit = function() {
FB.init({
appId : 'xxxxxxxx', // App ID
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
oauth : true, // enable OAuth 2.0
xfbml : true // parse XFBML
});
(function(d){
var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
js = d.createElement('script'); js.id = id; js.async = true;
js.src = "//connect.facebook.net/en_US/all.js";
d.getElementsByTagName('head')[0].appendChild(js);
}(document));
On the Login Page:
<fb:login-button scope="email" autologoutlink="true"></fb:login-button>
Is is possible to use PHP SDK to get the Facebook User ID?
Is it necessary to load Facebook JavaScript file before using PHP SDK?
This code gets the user data and serializes it, and throws to the database, i know its not perfect but have a look. I’m going to edit this when i get some free time, then i recommend encoding the users data as JSON, not as base64 serialized, because it will be easier to do query searches in the future.
U can get the values you want with JavaScript then pass them as values on the header, by the “location” function, then the php would get those info with $_GET, by i do recommend using the PHP SDK to do the auth stuff. But you choose. And you can also use them together.