Login with Google Account OpenID
Wall Script
Wall Script
Sunday, July 17, 2011

Login with Google Account OpenID

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.

Login with Google open id


Download Script     Live Demo

Update Articles
Login with Google Account OAuth
Login with Google Plus OAuth.

Developer
Ravi Tamada
Ravi Tamada
Designer Developer & Freelance
Chennai, INDIA
androidhive.info


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)
);

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

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());
?>

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>

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'] >

If any queries please comment here.
web notification

135 comments:

  1. nice and excellent tut, but in demo some redirect errors..

    ReplyDelete
  2. can we log out this time? =)

    ReplyDelete
  3. يا سلعة تفتق على ع الأخر

    ReplyDelete
  4. oauth_uid doesn't post to the users table? value is '0'?

    ReplyDelete
  5. nice tuto...everything make easy now....

    thanks

    ReplyDelete
  6. You are the man...Thanks!

    ReplyDelete
  7. 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.

    ReplyDelete
  8. Hey, it's easy to login with Google. Thanks for tut. it is great.

    ReplyDelete
  9. Thanks! Looks easier that FB login.

    ReplyDelete
  10. i am not able to get the script :(

    Please help

    Thanks

    ReplyDelete
  11. Thanks for sharing the post. Nice tutorial. Would like to try it.

    ReplyDelete
  12. hi its really bice

    ReplyDelete
  13. is the oauth_uid supposed to be 0?

    ReplyDelete
  14. very nice bt how to download

    Please help

    ReplyDelete
  15. very nice tutorial, i like. thanks.

    ReplyDelete
  16. @Kamran

    Server CPU overload please try after sometime.

    ReplyDelete
  17. when i use it on localhost then line no 86 of openid.php gives error in curl and wrapper() functions.

    ReplyDelete
  18. When click on google login then it takes too much execution time and i got following error

    Fatal error: Maximum execution time

    ReplyDelete
  19. 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 ?

    ReplyDelete
  20. I get this error

    Notice: Undefined variable: uid in D:\www\google-openid\getGoogleData.php on line 11

    ReplyDelete
  21. Me too getting the same error as Zern. author! please respond..

    ReplyDelete
  22. 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

    ReplyDelete
  23. Kurwa w chuj to nie działa !

    ReplyDelete
  24. Wow so nice! I like this site.Keep it working every day

    ReplyDelete
  25. 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

    ReplyDelete
  26. thanks for the script. it works!!!

    ReplyDelete
  27. after clicking sign in button in gmail i got an FORBIDDEN error in my server. how to solve it. any help will be apriciated.

    ReplyDelete
  28. It only works for @gmail.com accounts, not for other Google Accounts..

    ReplyDelete
  29. 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!

    ReplyDelete
  30. 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

    ReplyDelete
  31. Duniyaa me wo karo jo tumhe shi lage

    ReplyDelete
  32. oauth_uid doesn't post to the users table?
    isn't there a oauth id at google ?

    thanks !

    ReplyDelete
  33. It stores only my username and email address.. why??????????

    ReplyDelete
  34. How to get country and language?

    ReplyDelete
  35. 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.

    ReplyDelete
  36. Java sample code is available?

    ReplyDelete
  37. 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

    ReplyDelete
  38. i got forbidden error on my server while redirecting to getGoogleData.php

    ReplyDelete
  39. Do not know about it. Google really surprised me again, as well as information on your blog))

    ReplyDelete
  40. Do you know if this process also supports login in with a Google Apps account?

    ReplyDelete
  41. 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.

    ReplyDelete
  42. Awesome. Good work & a Great post

    ReplyDelete
  43. Thank you for tutorial
    Now just get only email.

    I would like to ask question : How to get contact detail (country, city, phone, street,...)

    ReplyDelete
  44. 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

    ReplyDelete
  45. how to dowload this?

    ReplyDelete
  46. Live demo url is not working, please check it.

    ReplyDelete
  47. Always nice stuff here! love it! tx

    ReplyDelete
  48. 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
    [email protected]

    ReplyDelete
  49. I think almost all of us are using Google account so it is very convenient. Thanks for share.

    ReplyDelete
  50. This comment has been removed by the author.

    ReplyDelete
  51. How can we do this login in a popup and get the data in the parent window?

    ReplyDelete
  52. 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)

    ReplyDelete
  53. 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.

    ReplyDelete
  54. Hi Srinivas.
    Instead of domain name i used the localhost . i am getting empty page . is localhost domain name work ?

    Thanks advance ..

    ReplyDelete
  55. Good Tute, But if you cance the "No Thanks" Info, it does not redired in "Demo"

    ReplyDelete
  56. 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

    ReplyDelete
  57. Thanks , thanks a lot , it also working localhost also.

    Thank you so much..

    :-)

    ReplyDelete
  58. how to download its not working i had subcribed also till it saying plz subscribe...

    ReplyDelete
  59. Excellent, Excellent, Excellent ...

    ReplyDelete
  60. Excellent code... Work fine. Now i want to logout too. (Single logout). Please help...

    ReplyDelete
  61. I am regular viewer of this site and have download so many script from this site. Thanks

    ReplyDelete
  62. 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.

    ReplyDelete
  63. 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é

    ReplyDelete
  64. 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.

    ReplyDelete
  65. 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

    ReplyDelete
  66. 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."

    ReplyDelete
  67. 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.

    ReplyDelete
  68. $uid not valid , what it's mean ? Can you explain it for me ?

    ReplyDelete
  69. 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.

    ReplyDelete
  70. i m facing the same issue as suresh mentioned earlier .. hope u solve this issue..

    ReplyDelete
  71. It's working nice....

    Thank u ravi

    ReplyDelete
  72. 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?

    ReplyDelete
  73. hi......... thanks for great tutorial it also simple for understand..........

    ReplyDelete
  74. what are the following files?
    where to get these files?


    getGoogleData.php //The Callback URL file
    login-google.php

    ReplyDelete
  75. 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!

    ReplyDelete
  76. hiiiiiiiiiiiiiiiiii this is great plugin but url redirect problem ocarr.

    ReplyDelete
  77. Hey nice tutorial man... U make it so easy... Thanks buddy!!

    ReplyDelete
  78. 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

    ReplyDelete
  79. 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.

    ReplyDelete
  80. Hi,

    Openid support HTTPS?

    Because am getting "Error in parsing the OpenID auth request." Error.

    Thanks in advance.

    ReplyDelete
  81. php boss neengathan you know tamil sir i love u ur hard work

    ReplyDelete
  82. Hi...,

    How to restrict my users to login only with their Google apps account using above method?

    ReplyDelete
  83. Is it possible in blogger blog

    ReplyDelete
  84. Thanks a lot ..superb job dude. simple and easy to undersatand

    ReplyDelete
  85. How much user details i can fetch from gmail login to my database, please help me...

    ReplyDelete
  86. Why am i getting this error ?
    You don't have permission to access /google-o/getGoogleData.php on this server.

    ReplyDelete
  87. You don't have permission to access /google-o/getGoogleData.php on this server.

    ReplyDelete
  88. thank you.
    everything 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.

    ReplyDelete
  89. Just Awesome.Great!
    Do we need to provide oauth key or any API key?

    ReplyDelete
  90. I got this Error and also empty $uid is inserting to DB

    Warning: 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

    ReplyDelete
  91. very nice tutorial, i like.
    Thanks for this article.

    ReplyDelete
  92. Awesome 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?

    ReplyDelete
  93. its work perfectly fine in local host , but when i upload it on bigrock server and change

    $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

    ReplyDelete
  94. NIce article but how to download the code ?

    ReplyDelete
  95. You 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

    ReplyDelete
  96. how can I get it to ask for additional fields that user has to fill manually before it completes the registration?

    ReplyDelete
  97. Hi Srini,
    I 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..

    ReplyDelete
  98. Error: invalid_request
    Error in parsing the OpenID auth request.

    ReplyDelete
  99. nice one man, just what i was looking for! thank you.

    ReplyDelete
  100. Hey bro,I don't know php ...can you tell me how to login gmail using asp.net???pls reply me.

    ReplyDelete
  101. u say change ur domain so plz exp how can i

    ReplyDelete
  102. I was looking for Facebook login for my site. Thanks for the post.

    ReplyDelete
  103. Hello friend , register domain problem , how to resolve it?

    ReplyDelete
  104. I have seen many websites are using Whatsapp button on it. I want to use the same

    ReplyDelete
  105. Hello, this demo doesn't work, OpenID has a new version and it's necessary migrate to it.

    Please can you update this example? Thank you.

    ReplyDelete
  106. how can I get it to ask for additional fields that user has to fill manually before it completes the registration?

    ReplyDelete

mailxengine Youtueb channel
Make in India
X