Few months back we had posted an article about login with Twitter and Facebook, it is most popular on 9lessons.info. We developed a system to quick login with Google account using OpenID authentication. This script helps you to avoid registration forms and email verification system, It’s is very quick, useful and simple to integrate.

Download Script
Live DemoDeveloper

Database
Sample database users 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)
);
(
id INT PRIMARY KEY AUTO_INCREMENT,
email VARCHAR(70),
oauth_uid int(11),
oauth_provider VARCHAR(100),
username VARCHAR(100)
);
In this tutorial we have the following directory structure
google-open //Google LightOpenID library
config
-- functions.php
-- dbconfig.php //Database connection
index.php
home.php
getGoogleData.php //The Callback URL file
login-google.php
config
-- functions.php
-- dbconfig.php //Database connection
index.php
home.php
getGoogleData.php //The Callback URL file
login-google.php
dbconfig.php
Database configuration file.
<?php
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) or die(mysql_error());
$database = mysql_select_db(DB_DATABASE) or die(mysql_error());
?>
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) or die(mysql_error());
$database = mysql_select_db(DB_DATABASE) or die(mysql_error());
?>
login-google.php
In root directory find out the below line at login-google.php code and replace yourdomain.com with your own domain value.
define('CALLBACK_URL', 'http://yourdomain.com/getGoogleData.php');
index.php
If you want to modify your web project existing login or index pages, just use following code.
<?php
session_start();
if (isset($_SESSION['id'])) {
// Redirect to home page as we are already logged in
header("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>
session_start();
if (isset($_SESSION['id'])) {
// Redirect to home page as we are already logged in
header("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>
home.php
In home page you can display user details by accessing session variables.
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'] >









nice and excellent tut, but in demo some redirect errors..
So sweet :)
nice man.
Nice tuto !
can we log out this time? =)
Thanks..
cool
Thanks Ravi :)
يا سلعة تفتق على ع الأخر
oauth_uid doesn't post to the users table? value is '0'?
nice tuto...everything make easy now....
thanks
You are the man...Thanks!
cooooool
Its awesme Ravi :)
I click on Download script & Demo link & got below error
http://analytics.hosting24.com/high_cpu.htmlsubscribe/index_google.php
Not Found
The requested URL /high_cpu.htmlsubscribe/index_google.php was not found on this server.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
Hey, it's easy to login with Google. Thanks for tut. it is great.
Great help.. thanks.
awesome
Thanks! Looks easier that FB login.
very nice bt how to download
i am not able to get the script :(
Please help
Thanks
Thanks for sharing the post. Nice tutorial. Would like to try it.
hi its really bice
is the oauth_uid supposed to be 0?
very nice bt how to download
Please help
very nice tutorial, i like. thanks.
@Kamran
Server CPU overload please try after sometime.
when i use it on localhost then line no 86 of openid.php gives error in curl and wrapper() functions.
When click on google login then it takes too much execution time and i got following error
Fatal error: Maximum execution time
Fatal error: Uncaught exception 'ErrorException' with message 'You must have either https wrappers or curl enabled.' in C:\AppServ\www\login\google\google-open\openid.php:86 Stack trace: #0 C:\AppServ\www\login\google\login-google.php(14): LightOpenID->__construct() #1 C:\AppServ\www\login\google\login-google.php(10): gooleAuthenticate() #2 {main} thrown in C:\AppServ\www\login\google\google-open\openid.php on line 86
I got this . Can you help me to solve the problem ?
cool
I get this error
Notice: Undefined variable: uid in D:\www\google-openid\getGoogleData.php on line 11
Me too getting the same error as Zern. author! please respond..
i am trying to download it ..
but it told me that my email no subscribed
although i subscribed it
plz find to me way to download this
as i need it asap
srry for my poor english
thnx in advance
Kurwa w chuj to nie działa !
nice
Wow so nice! I like this site.Keep it working every day
Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /mnt/154/sdb/5/8/whereisstef/google-open/openid.php on line 49
thanks for the script. it works!!!
after clicking sign in button in gmail i got an FORBIDDEN error in my server. how to solve it. any help will be apriciated.
It only works for @gmail.com accounts, not for other Google Accounts..
Hi there! this is one of the most useful script for me at the time..thnk u!!
I need a little favour can we login with gmail account without going on the gmail login page.
Plzz suggest me!! i'll waiting for ur feedback..
tahnk u!
Is it really secure?
I can login on example page with your credentials.
http://demos.9lessons.info/google-openid/getGoogleData.php?openid.ext1.value.firstname=Ravi&openid.ext1.value.email=ravi8x%40gmail.com&openid.ext1.value.lastname=Tamada
Duniyaa me wo karo jo tumhe shi lage
oauth_uid doesn't post to the users table?
isn't there a oauth id at google ?
thanks !
It stores only my username and email address.. why??????????
How to get country and language?
Here, using this Google API you can get only the three vales name and email info. you can't get gender , profile photo and other info you can't get here. for that you have to go to Google plus API.
Thanks. Try your best! :)
Java sample code is available?
hi srinivas, when i logged-out,then press login again,why it shows that i've logged in,whereas i login not yet in login
i got forbidden error on my server while redirecting to getGoogleData.php
fantastic
Do not know about it. Google really surprised me again, as well as information on your blog))
Do you know if this process also supports login in with a Google Apps account?
Hello Srinivas
i have a problem in 'oauth_uid' What is this for as no value is entered when the user logs in? Please Help, I think may have this problem.
Awesome. Good work & a Great post
Thank you for tutorial
Now just get only email.
I would like to ask question : How to get contact detail (country, city, phone, street,...)
Hi
I really like you posts
recently i am subscribed in your site but i got the conformation mail and clicked that but when i am trying to download the script still asking the confomation
Please help me on this
how to dowload this?
Live demo url is not working, please check it.
Always nice stuff here! love it! tx
Hi, srinivas
Veerendra here i implemented your login with facebook and twitter in my joomla project and its working fine thanks but i have a problem with login google as when it redirect back to my site after entering credentials at google account its gives me 403 forbidden error i tried giving 777 permission to the file but then it stop calling the file what to do please give suggetion hope you will revert
veerendra raghuvanshi
php developer
veerendra2406@gmail.com
I think almost all of us are using Google account so it is very convenient. Thanks for share.
Good
How can we do this login in a popup and get the data in the parent window?
Nice tutorial as usual... i want to download but ...(New subscribers email data update every 18 hours... i have waintin more than a day, but it doesnt accept my email subscribe)
hi i got this errors when try to login with this
You don't have permission to access /int/sign_in.php on this server.
Hi Srinivas.
Instead of domain name i used the localhost . i am getting empty page . is localhost domain name work ?
Thanks advance ..
Good Tute, But if you cance the "No Thanks" Info, it does not redired in "Demo"
Hi Srinivas,
I download this script in my server. unzip that script. http://localhost/google-openid/login-google.php page displays empty . Please help me .
Thanks
Thanks , thanks a lot , it also working localhost also.
Thank you so much..
:-)
how to download its not working i had subcribed also till it saying plz subscribe...
Excellent, Excellent, Excellent ...
Excellent code... Work fine. Now i want to logout too. (Single logout). Please help...
I am regular viewer of this site and have download so many script from this site. Thanks
hi thanks for great tutorial. After login to gmail, how can i get contact list. there is no function for this in functions.php file.
thanks
This tutorial works well but I need to get the User Google ID in addition to the names and email.
I did not find anyway to do so. Do you have any clue ?
Thanks in advance,
André
awesome work dude....:-)
Nice tutorial but when I'm running it on localhost I'm unable to be redirected to home.php page.
Can u please elaborate more on callback URL. what actually it is.
hi, great tutorial. although i get a 'Cannot modify header information - headers already sent by..'. It appears to work once I bypass your index.php page and run google_login.php directly. Is there a way around this ? thanks
I get this and couldn't it:
"You don't have permission to access /phpinc/fbtlogin/getGoogleData.php on this server.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request."
keep getting this
You don't have permission to access /phpinc/fbtlogin/getGoogleData.php on this server.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
$uid not valid , what it's mean ? Can you explain it for me ?
The logout is not clearing the session values. I am still logged in after clicking logout... anything wrong with the script. It's a great script though.
Nice script...
Thank You....
i m facing the same issue as suresh mentioned earlier .. hope u solve this issue..
It's working nice....
Thank u ravi
got this error,
Error: invalid_request
Error in parsing the OpenID auth request.
can anyone help me?? and one more thing,
$userdata = $user->checkUserGoogle($uid, 'Google', $username, $email);
this line is in getGoogleData.php, where is the $uid comes from?
hi......... thanks for great tutorial it also simple for understand..........
what are the following files?
where to get these files?
getGoogleData.php //The Callback URL file
login-google.php
Hi! This is really great but I'm just wondering if this can be done using Ajax? If so, do you have a code for that one..? Thanks!
hiiiiiiiiiiiiiiiiii this is great plugin but url redirect problem ocarr.
Hey nice tutorial man... U make it so easy... Thanks buddy!!
Fatal error: Uncaught exception 'ErrorException' with message 'You must have either https wrappers or curl enabled.' in /data/multiserv/users/970671/projects/2220318/www/google-open/openid.php:86 Stack trace: #0 /data/multiserv/users/970671/projects/2220318/www/login-google.php(14): LightOpenID->__construct() #1 /data/multiserv/users/970671/projects/2220318/www/login-google.php(10): gooleAuthenticate() #2 {main} thrown in /data/multiserv/users/970671/projects/2220318/www/google-open/openid.php on line 86
what i do
Hi dude,
This is really very nice stuff,but can somebody explain me what is the value of $uid which is assined to $_SESSION['oauth_id'] = $uid; in getGoogleData.php file.
Thanks in advance.
Hi,
Openid support HTTPS?
Because am getting "Error in parsing the OpenID auth request." Error.
Thanks in advance.