October 2015


Nowadays all are feel irritated to fill the long text box of registration form. So they feel simply registered with Google integration. For website  its also Safe to avoid spam and irrelevant data while login using google.  Most of the website demanded this option. social login has become a most integrated one in all login forms. In this tutorial We will learn how to make a Login System with Google using Php and OAuth Api. User will login with their Google account, give permission to access basic profile, and their name with email will be stored in database.


What is OAuth (Authorization)

Google APIs use the OAuth 2.0 protocol for authentication and authorization. Google supports common OAuth 2.0 scenarios such as those for web server, installed, and client-side applications.

To begin, obtain OAuth 2.0 client credentials from the Google Developers Console. Then your client application requests an access token from the Google Authorization Server, extracts a token from the response, and sends the token to the Google API that you want to access. For an interactive demonstration of using OAuth 2.0 with Google (including the option to use your own client credentials), experiment with the OAuth 2.0 Playground.

Refer –

Simply- your are the owner of your website and you have all admin privileges, ‘Guest’ want to access your page and surf some stuff unless admin grants him with some additional permissions . you can give some permission relevant to ‘Guest’ Role  without sharing your identity and full privileges. This is exactly done by google  OAuth, allow users to Authorize our page with some privileges.

Let start Coding part for Login System with Google using Php and OAuth Api, before that we need to Register our domain with goolge


Before Coding We need to get CLIENT ID and SECRET KEY for the google, because before the function we need register our website and get CLIENT ID and SECRET KEY for authentication and authorization to our website

Steps for Getting CLIENT ID and SECRET KEY

Step 1 – Go to the Url
It will redirect to gmail login page after you login with your goole account. It redirect to Google Developer console.

Note – This developer console is everyhting for create Apis Related to the Google

Login System with Google using Php and OAuth Api

Step 2 – Create a New project with your project nameLogin System with Google using Php and OAuth Api

Step 3 – Click APIs & auth link and click credentials and  Oauth 2.0 client Id


Login System with Google using Php and OAuth Api

Login System with Google using Php and OAuth Api

Step 4 – Before that create Contest screen for product and email verification Login System with Google using Php and OAuth Api

Login System with Google using Php and OAuth Api

Step 5 – Select web Application and Enter you domain and redirect URL details and then get you credentials

Login System with Google using Php and OAuth Api

Finally you get your CLIENT ID and SECRET KEY.

got client id

Coding Step

Create database and table

Create config.php file for configuration with database.. enter Your CLIENT ID and SECRET KEY here and also domain redirect your.

Create redirect URL function google_login.php  and this code for authentication the user with google whether he gave correct credentials or not. if give correct credentials check it ans success page redirect to specified page and insert user data into database.  If it returns error redirect back to index.php. If api returns user details check with database if user email exist and do the necessary accordingly and redirect back to home.php

finally create link for login in index.php

Create welcome page with logout button in home.php

Create logout.php function

That’s it Enjoy the code.

Nowadays, We showed our data in Frid view web content for the client. so for every content we need to use Sorting for Client and also our benefits, But Sorting, searching, pagination is not a easy job in HTML tables with Php and mysql data. So many grid view framework out there, Here we Learn about table sorting in jquery.
DataTable.js is the most popular nowadays. Using jquery and mysql structure we are going to create very simple and easy table sorting functions.

Column sorting is a feature where user can sort the results either in ascending or descending order.

Demo                                                                 Download

Step1 : Setup your database and table in MySQL
Before you run this script make sure you have created a database and table in MySQL. Below is the sample sql command to create a database, table, and insert some dummy rows.

For connect database Check this

Step 2: Fetch records from table and display
Now the next step is simple, fetch all records from MySQL table and display.

Step 3: Include jquery functions for sorting

Step 4 : Add css style for design

construct the table with id ‘table_srot’ and use this id for sorting. thead tag is required for using tablesorter. tbody tag is also required for using tablesorter. using mysql fetching with array you can get the data and using “exact” function you can access exect row asc or dec.
That’s it enjoy the code.