PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, February 11, 2022

[FIXED] Facebook login using PHP or javascript

 February 11, 2022     facebook, facebook-javascript-sdk, facebook-login, facebook-php-sdk     No comments   

Issue

i am a enthusiast for coding with limited knowledge of PHP & general coding terminologies. in my website, i have PHP at server and have/can-have Javascript at client. i want users to login using facebook (although users can register and login at my website). As of now users are required to provide a valid mail-ID and password to login by Conventioanl/Normal login method. i have registered the website at facebook apps and got the App ID and secret. but from none of the guides, i can figure out what is good for me, whether to have javascript or PHP SDK as register/login process.

i tried javascript SDK and clicking on "faccebook login" button would Pop-up dialogue, click "ok", and then i am unable to initiate session at server. Conventioanl/Normal login would through "Welcome Mr User-name" at client. How to tell server that user has provided his facebook credentials and is "ok"? and then how to land the user into his home page?

PHP SDK is going over my head. What action would be taken by user at client? Is it using some javascript at client? How this trigger would go to server along with his facebook user-ID and password? how to extract user's mail-ID after facebook is "ok"? and finally how to land the user into his home page at my server?

i can provide the code, if needed.

Please help me in plain english.


Solution

The best (and recommended) way to implement user authorization with the Facebook API is to use the JavaScript SDK. It is by far the most easy one, and the best for usability. With the PHP SDK you need to redirect the user to the authorization page. The JavaScript SDK just opens a popup for that and the user stays on the page.

One more benefit of using the JavaScript SDK is that you never need a page reload for refreshing the user session (which is valid for ~2 hours normally). Just use FB.getLoginStatus on page load and it will detect if the user is authorized already and refresh the session.

Here is all the information you need (basics, user authorization, authorization check):

  • https://developers.facebook.com/docs/javascript/quickstart/v2.1
  • https://developers.facebook.com/docs/reference/javascript/FB.login/v2.1
  • https://developers.facebook.com/docs/reference/javascript/FB.getLoginStatus

What you do after login is up to you, so you can save the user details in your database with AJAX, for example.



Answered By - andyrandy
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing