Facebook login implementation
-
27-10-2019 - |
Question
I have a website where I want to implement the facebook-login facility.. I went through the facebook developers pages, but they are kinda vague and unable to understnad completely.
My website is a php-mysql application, I already have a signing up process for new users in my website, but I want users to have an option of logging in with their facebook ID's and also, once they login, I want to store their ID's in my mysql database to identify them next time.
I have gone through similar topics in SO, but unable to crack it. If anybody could link me to a step-by-step clear guide to implement this on my website.
Solution
have a look at
OTHER TIPS
Just did a quick Google search on this and found the following blog post: link. Seems to cover setting up an FB login in php.
The post says that when you call $facebook->require_login();
it prompts the user to login using FB and then upon successful logging-in, returns you an FB id so you could write something like $fb_id = $facebook->require_login();
and then store $fb_id
.
Here's the full hello world example - best to read through the blog post for a more complete tutorial:
<?php
/* include the PHP Facebook Client Library to help
with the API calls and make life easy */
require_once('facebook/client/facebook.php');
/* initialize the facebook API with your application API Key
and Secret */
$facebook = new Facebook(YOUR_API_KEY,YOUR_SECRET_CODE);
/* require the user to be logged into Facebook before
using the application. If they are not logged in they
will first be directed to a Facebook login page and then
back to the application's page. require_login() returns
the user's unique ID which we will store in fb_user */
$fb_user = $facebook->require_login();
/* now we will say:
Hello USER_NAME! Welcome to my first application! */
?>
Hello <fb:name uid='<?php echo $fb_user; ?>' useyou='false' possessive='true' />! Welcome to my first application!
<?php
/* We'll also echo some information that will
help us see what's going on with the Facebook API: */
echo "<pre>Debug:" . print_r($facebook,true) . "</pre>";
?>