We have been published Facebook, Twitter and Google login authentication tutorial in our previous posts. Today we will discuss about one of the popular social network login oauth in PHP. In this tutorial you can learn how to integrate login with LinkedIn using PHP. We have developed simple PHP script for login with LinkedIn. LinkedIn login API script is used oauth library to connect with LinkedIn in PHP.
Our LinkedIn login API tutorial provides you an easy way to build login with LinkedIn using PHP. You can store LinkedIn user data at the database using MySQL. Let’s start the LinkedIn oAuth PHP tutorial.
You can check the live demo of LinkedIn login API with PHP from the above Demo link and also able to download the complete project from the above Download link.
This project has three folders named
includes/ and some PHP files. The folders and files structure are given below:
LinkedIn App Creation:
Go to the Apps page at LinkedIn Developer Network and login with your LinkedIn account credentials – https://www.linkedin.com/secure/developer
Click on the Add New Application link for create new App.
Enter the new application details into the app registration form.
Company Info: If you already have not any company page, select “New Company” and enter your company name.
Application Info: Enter all the application details and select “Live” option as “Live Status”.
Contact Info: Enter your contact details.
OAuth User Agreement: Select the “Default Scope” and enter “Redirect URLs” (
http://localhost/login_with_linkedin_using_php/process.php), “Accept Redirect URL” (
http://localhost/login_with_linkedin_using_php/process.php), “Cancel Redirect URL” (
Click on the Add Application button.
Once the application is created successfully, application details would be displayed.
Keep the API Key and Secret Key for later use.
Database table creation:
To store the user information, you need to create a database and a table. At first create a database like
codexworld. After that copy the below SQL query and run the SQL query on the database.
CREATE TABLE `users` ( `id` int(11) NOT NULL AUTO_INCREMENT, `oauth_provider` varchar(255) COLLATE utf8_unicode_ci NOT NULL, `oauth_uid` varchar(255) COLLATE utf8_unicode_ci NOT NULL, `fname` varchar(255) COLLATE utf8_unicode_ci NOT NULL, `lname` varchar(255) COLLATE utf8_unicode_ci NOT NULL, `email` varchar(255) COLLATE utf8_unicode_ci NOT NULL, `location` varchar(255) COLLATE utf8_unicode_ci NOT NULL, `country` varchar(50) COLLATE utf8_unicode_ci NOT NULL, `picture_url` varchar(255) COLLATE utf8_unicode_ci NOT NULL, `profile_url` varchar(255) COLLATE utf8_unicode_ci NOT NULL, `created` datetime NOT NULL, `modified` datetime NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci
In this project you just have to modify only two files.
Database configuration (
db.php file have
DB class with some functions. This
DB class is used for managing the LinkedIn user data into the database. Into the
dbConnect() function we have configured the database and connect with the database. You need only to change the
$dbName variables value with your MySQL server details.
// database configuration
$dbServer = 'localhost';
$dbUsername = 'root';
$dbPassword = '';
$dbName = 'codexworld';
$conn = new mysqli($dbServer,$dbUsername,$dbPassword,$dbName);
$this->db = $conn;
die("Database conection error: ".$conn->connect_error);
LinkedIn API configuration (
config.php): open the
config.php file and modify the
$linkedinApiSecret variables value.
Note that: You can find the Authentication Keys from your LinkedIn Apps details page.
$baseURL = 'http://localhost/login-with-linkedin-using-php/';
$callbackURL = 'http://localhost/login-with-linkedin-using-php/process.php';
// LinkedIn Authentication Keys
$linkedinApiKey = 'LinkedIn Client ID';
$linkedinApiSecret = 'LinkedIn Client Secret';
// LinkedIn Application Permissions
$linkedinScope = 'r_basicprofile r_emailaddress';
If you have any query about this tutorial and scripts, feel free to comment here.