How to Login with Google Account OpenID | Haak Blog

This post explains you about how to Login with Google account OpenID authentication in PHP.

OpenID is an open standard that describes how users can be authenticated in a manner that is decentralized, allowing users to consolidate their digital identities and eliminating the requirement for services to provide their particular ad hoc systems.

This is only because the OpenId supplier is trusted to have verified all details of the user.
Login with Google Account OpenID
Accepting OpenId login on a site has advantages like :
  1. Quick form-less enrollment for users. Makes user experience. Thus increased enrollment/conversion rates.
  2. Lesser validation of user information like e-mail verification etc.
  3. Faster logins. Users are mainly logged in for their preferred openid suppliers, and so the login happens simply by making a click!
Over here we shall see just how to execute the "Login with Google Account OpenID" attribute to some website using Google's openid supplier.

Login with Google Account OpenID

Following below steps to How to Login with Google Account OpenID:

1. Database

Create database user table columns id, email, oauth_uid, oauth_provider and username.
CREATE TABLE users(id INT PRIMARY KEY AUTO_INCREMENT,email VARCHAR(70), oauth_uid int(11),oauth_provider VARCHAR(100),username VARCHAR(100) );

2. Database Configuration

Create database and add details of your database in dbconfig.php file as like below:
define('DB_SERVER', 'dbserver');define('DB_USERNAME', 'username');define('DB_PASSWORD', 'password');define('DB_DATABASE', 'database');
define('USERS_TABLE_NAME', 'users_table_name'); //Replace your users table name here$connection = mysql_connect(DB_SERVER, DB_USERNAME, DB_PASSWORD) ordie(mysql_error());$database = mysql_select_db(DB_DATABASE) or die(mysql_error());?>

3. Google Login Config File

Edit login-google.php file that you can find in root directory and replace to your website URL.
define('CALLBACK_URL', '');

4. Index Page Configuration

If you add login on your exiting page than add following code on your index page:
<?phpsession_start();if (isset($_SESSION['id'])) {// Redirect to home page as we are already logged inheader("location: home.php");}if (array_key_exists("login", $_GET)) {$oauth_provider = $_GET['oauth_provider'];if ($oauth_provider == 'google'){header("Location: login-google.php");}}?>//HTML Code<a href="?login&oauth_provider=google">Google Login</a>

5. Home.php Configuration

Name: <?php $_SESSIONS['username'] >Email: <?php $_SESSIONS['email'] >Your are logged in with: <?php $_SESSIONS['oauth_provider'] ><a href="logout.php?logout">Logout</a> from  <?php $_SESSIONS['oauth_provider'] >

Download Script Now

Google Account OpenID

Post a Comment