Facebook Open Authentication in PHP

Open authentication is for providing access to the server resources after authorizing users via third party services. It will take place between open authentication providers and websites implementing open authentication.

In this tutorial, we are going to see about implementing Facebook open authentication with our website using PHP. We can achieve this login mechanism using Facebook API.

Steps for Facebook Open Authentication

Register as the Facebook developer.

Create a new Facebook application to get Facebook API key and secret key.

We are getting login and logout URL by using Facebook API class functions. These URLs are used for respective hyperlinks.

By using PHP Facebook SDK, the user sessions and cookies will remain even after log out. So, it is hard to display login or logout links based on the Facebook login status.

To solve this problem, we are sending last action performed with redirect URLs of getLoginUrl() and getLogoutUrl() functions. Based on these actions, we can maintain the session to show respective hyperlinks.

output:

While running this program, it will show Facebook login button.

While clicking this Facebook login button, it will redirect to the facebook login page.