Gmail login in php easy step to learn
Hello, guys. In this tutorial I will discuss a good topic which will be more helpful for you. The topic is Google Login system with PHP. Login system connect in your website is very easy step.
Now on every web site we see that there is a Google login option. So implement google login system on your website very quick and easily. This tutorial so much help to to do it fast on your website. The Google API Client Library enables with Google services like Google+.
If you want to give a option of Google Login to the user for their sign up or sign in, then It will be very expensive for you. Here you can also use the library to fetch user details. You can also required for user registration and user login system.
Follow all steps and example code and try it fast. Use Google API Client Library to make user registration and login system on your website.
Login System in PHP
Step 1 : At first generate google API and secret key from https://console.developers.google.com this link and download the “GoogleClient” and “Google Oauth2Service“.
Step 2 : create a php file named index.php containing following codes
<?php require_once('gpConfig.php'); require_once('User.php'); if(isset($_GET['code'])){ $gClient->authenticate($_GET['code']); $_SESSION['token'] = $gClient->getAccessToken(); header('Location: ' . filter_var($redirectURL, FILTER_SANITIZE_URL)); } if (isset($_SESSION['token'])) { $gClient->setAccessToken($_SESSION['token']); } $authUrl = $gClient->createAuthUrl(); ?>
Step 3 : create a php file named gpConfig.php containing following codes
<?php require_once( 'src/Google_Client.php'); require_once('src/contrib/Google_Oauth2Service.php'); $clientId = 'xxxxxxxx'; //Google client ID $clientSecret = 'xxxxxxxxxxx'; //Google client secret $redirectURL = 'http://xxxxxx.com'; //Callback URL //Call Google API $gClient = new Google_Client(); $gClient->setApplicationName('Login to CodexWorld.com'); $gClient->setClientId($clientId); $gClient->setClientSecret($clientSecret); $gClient->setRedirectUri($redirectURL); $google_oauthV2 = new Google_Oauth2Service($gClient); ?>
Step 4 : create a php file named User.php containing following codes
<?php class User { function checkUser($userData = array()){ //Return user data return $userData; } } ?>
Step 5 : create a redirect page, after login in gmail the user info will be available here. create a php page named redirect_page.php containing following codes.
<?php //echo 'test...'; include_once 'gpConfig.php'; include_once 'User.php'; if(isset($_GET['code'])){ $gClient->authenticate($_GET['code']); $_SESSION['token'] = $gClient->getAccessToken(); header('Location: ' . filter_var($redirectURL, FILTER_SANITIZE_URL)); } if (isset($_SESSION['token'])) { $gClient->setAccessToken($_SESSION['token']); } if ($gClient->getAccessToken()) { //Get user profile data from google $gpUserProfile = $google_oauthV2->userinfo->get(); //Initialize User class $user = new User(); //Insert or update user data to the database $gpUserData = array( 'oauth_provider'=> 'google', 'oauth_uid' => $gpUserProfile['id'], 'first_name' => $gpUserProfile['given_name'], 'last_name' => $gpUserProfile['family_name'], 'email' => $gpUserProfile['email'], 'gender' => $gpUserProfile['gender'], 'locale' => $gpUserProfile['locale'], 'picture' => $gpUserProfile['picture'], 'link' => $gpUserProfile['link'] ); $userData = $user->checkUser($gpUserData); //var_dump($userData); exit; print_r($userData); exit; } ?>
Thanking You
Click here: To get code of Push notification in 5 minutes in PHP
Thanks for visiting our blog. Follow our blog site because we have more PHP Tutorial and we have more tutorial related different type of programming language. You will be happy to know that the DataInFlow is a platform, where you can get the text tutorial and video tutorial of a different kind of programming language like PHP, HTML, Javascript, Jquery, CSS3 and get some more programming tutorial.
You much like DataInFlow.com because it provides you to ask any kind of programming questions and get answer in quick time. Also you can answer any others question if you know. If you have any programming question, so Click for ASK Here.
Absolutely NEW update of captchas solution software “XRumer 16.0 + XEvil 4.0”:
captcha recognition of Google (ReCaptcha-2 and ReCaptcha-3), Facebook, BitFinex, Bing, Hotmail, SolveMedia, Yandex,
and more than 8400 another subtypes of captchas,
with highest precision (80..100%) and highest speed (100 img per second).
You can use XEvil 4.0 with any most popular SEO/SMM programms: iMacros, XRumer, GSA SER, ZennoPoster, Srapebox, Senuke, and more than 100 of other software.
Interested? You can find a lot of impessive videos about XEvil in YouTube.
Free XEvil Demo available.
Good luck 😉
I love your blog.. very nice colors & theme. Did you create this website yourself or did you hire
someone to do it for you? Plz reply as I’m looking to construct
my own blog and would like to find out where u got this from.
thanks
Do you want to create blog like this?
Hurry up to look into loveawake.ru you will find a lot of interesting things
This post will help the internet users for creating new web site or even a weblog from start to end.
Hey very interesting blog!
Good post, But I haven’t more time to spend on it. Because I am reading an SEO company primelis related article. It’s very popular at this time