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 Demo
Update Articles
Login with Google Account OAuth
Login with Google Plus OAuth.
Developer
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..
ReplyDeleteSo sweet :)
ReplyDeletenice man.
ReplyDeleteNice tuto !
ReplyDeletecan we log out this time? =)
ReplyDeleteThanks..
ReplyDeletecool
ReplyDeleteThanks Ravi :)
ReplyDeleteيا سلعة تفتق على ع الأخر
ReplyDeleteoauth_uid doesn't post to the users table? value is '0'?
ReplyDeletenice tuto...everything make easy now....
ReplyDeletethanks
You are the man...Thanks!
ReplyDeletecooooool
ReplyDeleteIts awesme Ravi :)
ReplyDeleteI click on Download script & Demo link & got below error
ReplyDeletehttp://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.
ReplyDeleteGreat help.. thanks.
ReplyDeleteThanks! Looks easier that FB login.
ReplyDeletevery nice bt how to download
ReplyDeletei am not able to get the script :(
ReplyDeletePlease help
Thanks
Thanks for sharing the post. Nice tutorial. Would like to try it.
ReplyDeletehi its really bice
ReplyDeleteis the oauth_uid supposed to be 0?
ReplyDeletevery nice bt how to download
ReplyDeletePlease help
very nice tutorial, i like. thanks.
ReplyDelete@Kamran
ReplyDeleteServer 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.
ReplyDeleteWhen click on google login then it takes too much execution time and i got following error
ReplyDeleteFatal 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
ReplyDeleteI got this . Can you help me to solve the problem ?
cool
ReplyDeleteI get this error
ReplyDeleteNotice: Undefined variable: uid in D:\www\google-openid\getGoogleData.php on line 11
Me too getting the same error as Zern. author! please respond..
ReplyDeletei am trying to download it ..
ReplyDeletebut 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 !
ReplyDeletenice
ReplyDeleteWow so nice! I like this site.Keep it working every day
ReplyDeleteParse 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
ReplyDeletethanks for the script. it works!!!
ReplyDeleteafter clicking sign in button in gmail i got an FORBIDDEN error in my server. how to solve it. any help will be apriciated.
ReplyDeleteIt only works for @gmail.com accounts, not for other Google Accounts..
ReplyDeleteHi there! this is one of the most useful script for me at the time..thnk u!!
ReplyDeleteI 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?
ReplyDeleteI 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
ReplyDeleteoauth_uid doesn't post to the users table?
ReplyDeleteisn't there a oauth id at google ?
thanks !
It stores only my username and email address.. why??????????
ReplyDeleteHow to get country and language?
ReplyDeleteHere, 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.
ReplyDeleteThanks. Try your best! :)
ReplyDeleteJava sample code is available?
ReplyDeletehi srinivas, when i logged-out,then press login again,why it shows that i've logged in,whereas i login not yet in login
ReplyDeletei got forbidden error on my server while redirecting to getGoogleData.php
ReplyDeletefantastic
ReplyDeleteDo not know about it. Google really surprised me again, as well as information on your blog))
ReplyDeleteDo you know if this process also supports login in with a Google Apps account?
ReplyDeleteHello Srinivas
ReplyDeletei 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
ReplyDeleteThank you for tutorial
ReplyDeleteNow just get only email.
I would like to ask question : How to get contact detail (country, city, phone, street,...)
Hi
ReplyDeleteI 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?
ReplyDeleteLive demo url is not working, please check it.
ReplyDeleteAlways nice stuff here! love it! tx
ReplyDeleteHi, srinivas
ReplyDeleteVeerendra 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
[email protected]
I think almost all of us are using Google account so it is very convenient. Thanks for share.
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteHow can we do this login in a popup and get the data in the parent window?
ReplyDeleteNice 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)
ReplyDeletehi i got this errors when try to login with this
ReplyDeleteYou don't have permission to access /int/sign_in.php on this server.
Hi Srinivas.
ReplyDeleteInstead 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"
ReplyDeleteHi Srinivas,
ReplyDeleteI 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.
ReplyDeleteThank you so much..
:-)
how to download its not working i had subcribed also till it saying plz subscribe...
ReplyDeleteExcellent, Excellent, Excellent ...
ReplyDeleteExcellent code... Work fine. Now i want to logout too. (Single logout). Please help...
ReplyDeleteI am regular viewer of this site and have download so many script from this site. Thanks
ReplyDeletehi thanks for great tutorial. After login to gmail, how can i get contact list. there is no function for this in functions.php file.
ReplyDeletethanks
ReplyDeleteThis tutorial works well but I need to get the User Google ID in addition to the names and email.
ReplyDeleteI did not find anyway to do so. Do you have any clue ?
Thanks in advance,
André
awesome work dude....:-)
ReplyDeleteNice tutorial but when I'm running it on localhost I'm unable to be redirected to home.php page.
ReplyDeleteCan 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
ReplyDeleteI get this and couldn't it:
ReplyDelete"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
ReplyDeleteYou 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 ?
ReplyDeleteThe 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.
ReplyDeleteNice script...
ReplyDeleteThank You....
i m facing the same issue as suresh mentioned earlier .. hope u solve this issue..
ReplyDeleteIt's working nice....
ReplyDeleteThank u ravi
got this error,
ReplyDeleteError: 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..........
ReplyDeletewhat are the following files?
ReplyDeletewhere 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!
ReplyDeletehiiiiiiiiiiiiiiiiii this is great plugin but url redirect problem ocarr.
ReplyDeleteHey nice tutorial man... U make it so easy... Thanks buddy!!
ReplyDeleteFatal 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
ReplyDeletewhat i do
Hi dude,
ReplyDeleteThis 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,
ReplyDeleteOpenid support HTTPS?
Because am getting "Error in parsing the OpenID auth request." Error.
Thanks in advance.
php boss neengathan you know tamil sir i love u ur hard work
ReplyDeleteok thank you boss
ReplyDeleteHi...,
ReplyDeleteHow to restrict my users to login only with their Google apps account using above method?
Is it possible in blogger blog
ReplyDeleteThanks a lot ..superb job dude. simple and easy to undersatand
ReplyDeleteHow much user details i can fetch from gmail login to my database, please help me...
ReplyDeleteWhy am i getting this error ?
ReplyDeleteYou don't have permission to access /google-o/getGoogleData.php on this server.
You don't have permission to access /google-o/getGoogleData.php on this server.
ReplyDeletegreat
ReplyDeletegood tutorial.
ReplyDeletethank you.
ReplyDeleteeverything is working fine except the logout.php.
even though i click "logout from google" i am still logged-in in the gmail.
the session destroy is not logging me out from the gmail. please help me someone. thank you.
Just Awesome.Great!
ReplyDeleteDo we need to provide oauth key or any API key?
I got this Error and also empty $uid is inserting to DB
ReplyDeleteWarning: Cannot modify header information - headers already sent by (output started at /home/coremind/public_html/dev/config/functions.php:16) in /home/coremind/public_html/dev/getGoogleData.php on line 20
very nice tutorial, i like.
ReplyDeleteThanks for this article.
Nice cool, is very terrify!!
ReplyDeleteAwesome Srinivas. Loved it. Very easily installed on my website and working fine. Can I use OpenID for logging to Yahoo and other accounts as well?
ReplyDeleteits nice tutorial dude
ReplyDeleteNice tutorial thank you
ReplyDeleteits work perfectly fine in local host , but when i upload it on bigrock server and change
ReplyDelete$openid = new LightOpenID('localhost');
to
$openid = new LightOpenID('www.MyDomainName.com');
and
$openid->returnUrl = 'http://www.MyDomainName/xyz/login.php';
its showing error
Error: invalid_request
Error in parsing the OpenID auth request.
please suggest what necessary changes i need to do
Thanks
thanks
ReplyDeleteNIce article but how to download the code ?
ReplyDeleteGreat feature!
ReplyDeleteYou are GOD!! Bhai .. I have been breaking my head for last three days to make aPlugin which can access all three like google twitter and facebook.. twitter and facebook was no problem but google flow and structure I was making me Mad bcoz of URL redirection then I saw your tutorial which was based on OPEN ID and this is kick ass I would say ... thank you very much
ReplyDeletehow can I get it to ask for additional fields that user has to fill manually before it completes the registration?
ReplyDeleteHi Srini,
ReplyDeleteI am trying to send html form in email and the user can respond to it.
In case I am sending the html form to a gmail distribution list, how can I capture the gmail id of the person who is submitting the html form in email?
Any suggestions or workarounds are welcome..
Error: invalid_request
ReplyDeleteError in parsing the OpenID auth request.
nice one man, just what i was looking for! thank you.
ReplyDeleteHey bro,I don't know php ...can you tell me how to login gmail using asp.net???pls reply me.
ReplyDeletenice
ReplyDeleteu say change ur domain so plz exp how can i
ReplyDeleteI was looking for Facebook login for my site. Thanks for the post.
ReplyDeleteHello friend , register domain problem , how to resolve it?
ReplyDeletenice one
ReplyDeleteI have seen many websites are using Whatsapp button on it. I want to use the same
ReplyDeleteHello, this demo doesn't work, OpenID has a new version and it's necessary migrate to it.
ReplyDeletePlease can you update this example? Thank you.
how can I get it to ask for additional fields that user has to fill manually before it completes the registration?
ReplyDeletehai buddy...nice
ReplyDeletenyc one... :)
ReplyDelete