w3tweaks
  • Effects
    • Scroll Effects
    • Text Effects
    • Shadow
  • Essentials
    • Arrows
    • Buttons
    • Background Patterns
    • Border Examples
    • Cards
    • Color Palettes
    • Dividers
    • Link styles
    • Loaders
    • Modal Windows
    • Notifications
    • Progress bar
    • Quote styles
    • Spinner
    • Tooltips
  • Media
    • Calendars
    • Carousels
    • Clocks
    • Gallery
    • Music Players
    • Sliders
    • Slideshows
    • Tables
    • Thumbnails
  • Navigation
  • Inputs
    • Range Sliders
    • Checkboxes
    • Toggle Switches
  • Scripts
    • Angularjs
    • Backbone.js
    • bootstrap
    • jQuery
    • ReactJs
    • JavaScript
    • Syntax Highlighters
    • tryit editor
    • PHP
  • API’s
    • Facebook
    • Google
    • Indeed
    • Twitter
    • YouTube
w3tweaks
  • Effects
    • Scroll Effects
    • Text Effects
    • Shadow
  • Essentials
    • Arrows
    • Buttons
    • Background Patterns
    • Border Examples
    • Cards
    • Color Palettes
    • Dividers
    • Link styles
    • Loaders
    • Modal Windows
    • Notifications
    • Progress bar
    • Quote styles
    • Spinner
    • Tooltips
  • Media
    • Calendars
    • Carousels
    • Clocks
    • Gallery
    • Music Players
    • Sliders
    • Slideshows
    • Tables
    • Thumbnails
  • Navigation
  • Inputs
    • Range Sliders
    • Checkboxes
    • Toggle Switches
  • Scripts
    • Angularjs
    • Backbone.js
    • bootstrap
    • jQuery
    • ReactJs
    • JavaScript
    • Syntax Highlighters
    • tryit editor
    • PHP
  • API’s
    • Facebook
    • Google
    • Indeed
    • Twitter
    • YouTube
w3tweaks
Home Script php
Login using LinkedIn oAuth2 in php and MySQL

Login using LinkedIn oAuth2 in php and MySQL

Vetrivel Pandian by Vetrivel Pandian
November 27, 2019
in php
0

Today am showing to how make user authentication using LinkedIn API. First you have some knowledge about OAuth just read this official explanation, https://oauth.net/about/introduction/

Now a days most of students & peoples are hate to fill the registration form so everyone move on the new options for OAuth connection like Google, LinkedIn, Twitter etc.. So this is the reason of I have develop Login page with LinkedIn API.

You might also like

PHP Login system

13 Best PHP Login system

January 14, 2021
0
Collection of PHP Libraries for sending and parsing email

8 PHP Libraries for sending and parsing email

May 9, 2020
0

Create Application Linkedin

First, you have to create one new application in LinkedIn site. The link is https://www.linkedin.com/secure/developer . Like this image

create one new application in LinkedIn site

Fill the all fields that’s very simple. Then enter your Website URL or Localhost server URL, click submit.

Hereafter, the Client Id and Client Secret will be generated & add the redirect URL’s. Like this

linkedin client id and client secret

Now the LinkedIn code is over, hereafter you have to move on the php code. Download the zip file and unzip it. First open config.php file. Then just replace your own Client-Id and Client Secret key in your php code. The code is,

<?php
  $baseURL = 'http://www.w3tweak.com/linkedinlogin/';
  $callbackURL = 'http://www.w3tweaks.com/linkedinlogin/process.php';
  $linkedinApiKey = Client-ID';
  $linkedinApiSecret = 'Client-Secret';
  $linkedinScope = 'r_basicprofile r_emailaddress';
?>

Database Configuration

Now time to create database to store the user information like linkedin user information.

Create one database (database name is – linkedinlogin), then just import the user.sql file in your database.

That’s all the database code to store the user information.

Homepage for LinkedIn OAuth Login

The homepage design for LinkedIn click button when the user click this its directly redirect on LinkedIn site and get the information for user & authenticate with your website.

linkedin login button

The actual code for process.php to redirect and get the full access of LinkedIn information. Open process.php file.

<?php
session_start();
include_once("config.php");
include_once("includes/db.php");
include_once("LinkedIn/http.php");
include_once("LinkedIn/oauth_client.php");

//db class instance
$db = new DB;

if (isset($_GET["oauth_problem"]) && $_GET["oauth_problem"] <> "") {
  // in case if user cancel the login. redirect back to home page.
  $_SESSION["err_msg"] = $_GET["oauth_problem"];
  header("location:index.php");
  exit;
}

$client = new oauth_client_class;

$client->debug = false;
$client->debug_http = true;
$client->redirect_uri = $callbackURL;

$client->client_id = $linkedinApiKey;
$application_line = __LINE__;
$client->client_secret = $linkedinApiSecret;

if (strlen($client->client_id) == 0 || strlen($client->client_secret) == 0)
  die('Please go to LinkedIn Apps page https://www.linkedin.com/secure/developer?newapp= , '.
			'create an application, and in the line '.$application_line.
			' set the client_id to Consumer key and client_secret with Consumer secret. '.
			'The Callback URL must be '.$client->redirect_uri).' Make sure you enable the '.
			'necessary permissions to execute the API calls your application needs.';


$client->scope = $linkedinScope;
if (($success = $client->Initialize())) {
  if (($success = $client->Process())) {
    if (strlen($client->authorization_error)) {
      $client->error = $client->authorization_error;
      $success = false;
    } elseif (strlen($client->access_token)) {
      $success = $client->CallAPI(
					'http://api.linkedin.com/v1/people/~:(id,email-address,first-name,last-name,location,picture-url,public-profile-url,formatted-name)', 
					'GET', array(
						'format'=>'json'
					), array('FailOnAccessError'=>true), $user);
    }
  }
  $success = $client->Finalize($success);
}
if ($client->exit) exit;
if ($success) {
  	$user_id = $db->checkUser($user);
	$_SESSION['loggedin_user_id'] = $user_id;
	$_SESSION['user'] = $user;
} else {
 	 $_SESSION["err_msg"] = $client->error;
}
header("location:index.php");
exit;
?>

You have don’t change any code in process.php file.

Finally, view the LinkedIn OAuth in your website the output like

linkedin authendication

That’s all. If you have any doubt regarding this feel free to comment below.

Download
Demo

Tags: APIdemoexampleintegrationLinkedInloginmysqloauthoAuth2phpsystem
Previous Post

Angularjs and JSON list infinite scroll

Next Post

How to integrate the login using Google+ plus API in PHP

Vetrivel Pandian

Vetrivel Pandian

Related Stories

PHP Login system

13 Best PHP Login system

by W3TWEAKS
January 14, 2021
0
0

Find the collection of Hand-Picked free PHP Login system. Scripts all developed using PHP, MySql (Database), HTML, and CSS. Below...

Collection of PHP Libraries for sending and parsing email

8 PHP Libraries for sending and parsing email

by W3TWEAKS
May 9, 2020
0
0

Collection of PHP Libraries for sending and parsing email. CssToInlineStyles class PHP CssToInlineStyles is a class to convert HTML into HTML...

PHP Content Management Systems

8 PHP Content Management Systems (CMS)

by W3TWEAKS
May 9, 2020
0
0

Find the collection of PHP Content Management Systems. Back Drop CMS The free and Open Source CMS that helps you...

Login the App using facebook oauth in PHP

Login the App using facebook oauth in PHP

by W3TWEAKS
November 29, 2019
0
0

In my old articles, we see integration about how to login the apps using social networking in PHP like Twitter,...

Next Post
How to integrate the login using Google+ plus API in PHP

How to integrate the login using Google+ plus API in PHP

Discussion about this post

We bring you the best frontend collections that will fix perfect for news, magazine, personal blog, etc. Check our landing page for details.

  • Effects
    • Scroll Effects
    • Text Effects
    • Shadow
  • Essentials
    • Arrows
    • Buttons
    • Background Patterns
    • Border Examples
    • Cards
    • Color Palettes
    • Dividers
    • Link styles
    • Loaders
    • Modal Windows
    • Notifications
    • Progress bar
    • Quote styles
    • Spinner
    • Tooltips
  • Media
    • Calendars
    • Carousels
    • Clocks
    • Gallery
    • Music Players
    • Sliders
    • Slideshows
    • Tables
    • Thumbnails
  • Navigation
  • Inputs
    • Range Sliders
    • Checkboxes
    • Toggle Switches
  • Scripts
    • Angularjs
    • Backbone.js
    • bootstrap
    • jQuery
    • ReactJs
    • JavaScript
    • Syntax Highlighters
    • tryit editor
    • PHP
  • API’s
    • Facebook
    • Google
    • Indeed
    • Twitter
    • YouTube