Website login is very important part of web development, now era is change,so no person wants to fill registration form to login in website,You can solve this problem using OpenID. OpenID provides a safe and simple way for people to login into your website/blog without fill a registration form.You can use this code for other account as well like wordpress, yahoo aol ext except Facebook and twitter.You just need an account of OpenID provider to access login without registration form.
I will show you how to connect with Google and yahoo using OpenID provides.
Download auth file from below url.
Download OpenID
To create login page to get action index.php
.
<?php session_start(); # include google lib file. require 'openid.php'; try { # Change 'localhost' to your domain name. $openid = new LightOpenID('localhost'); $openid->required = array( 'namePerson', 'namePerson/first', 'namePerson/last', 'contact/email', ); if(!$openid->mode) { if(@$_GET['auth']=="google") { $_SESSION['auth']="Google"; $openid->identity = 'https://www.google.com/accounts/o8/id'; header('Location: ' . $openid->authUrl()); }elseif(@$_GET['auth']=="yahoo") { $_SESSION['auth']="Yahoo"; $openid->identity ='yahoo.com'; header("Location:".$openid->authUrl()); } } elseif($openid->mode == 'cancel') { echo 'User has canceled authentication!'; } else { $external_login=$openid->getAttributes(); $_SESSION['name']=$external_login['namePerson/first']." ".$external_login['namePerson/last']; $_SESSION['email']=$external_login['contact/email']; header("Location:home.php"); exit(); } } catch(ErrorException $e) { echo $e->getMessage(); } ?> <h1 class="center">Phpflow.com login</h1> <table width="200" border="0" align="center" cellpadding="5" cellspacing="0" style="border:1px solid #CCC;"> <tr> <td><form id="form1" name="form1" method="post" action-xhr="#"> <table width="100%" border="0" cellspacing="0" cellpadding="5"> <tr> <td>E-mail address</td> <td><label> <input type="text" name="user" id="user" /> </label></td> </tr> <tr> <td>Password</td> <td><label> <input type="text" name="pass" id="pass" /> </label></td> </tr> <tr> <td> </td> <td><label> <input type="submit" name="button" id="button" value="Submit" /> </label></td> </tr> </table> </form></td> </tr> <tr> <td bgcolor="#F6F6F6"> <a href="index.php?auth=google"> <img src="Google-login-button.png" alt="google Login" border="0" /></a> <a href="index.php?auth=yahoo"> <img src="http://l.yimg.com/a/i/reg/openid/buttons/17.png" alt="yahoo Login" border="0" /></a> </td> </tr> </table>
Step 3: To create home page to redirect after successful login home.php
.
<?php session_start(); if(!isset($_SESSION['auth'])) { header("Location:index.php"); exit(); } ?> <span><a href="sign-out.php">Sign Out</a></span> <div>Account Home : After Successful Login</div> You are Sign In with : <strong><?=$_SESSION['auth'] ?></strong> Account, User ID: <strong><?=$_SESSION['email'] ?></strong></td>
Result
Step 4: To create sign-out page to redirect after successful logout signout.php
.
<?php session_start(); session_destroy(); header("Location:index.php"); exit(); ?>
There are other account providers also available,You just have to change the url $openid->identity()
function by below url:
http://yourblog.wordpress.com
https://www.google.com/accounts/o8/id
http://www.google.com/profiles/\~YOURUSERNAME
https://me.yahoo.com
http://www.livejournal.com/openid/server.bml
https://www.aol.com
This tutorial helps integrate a PHP SDK with Laravel. We'll install aws-php-sdk into laravel application and access all aws services… Read More
in this quick PHP tutorial, We'll discuss php_eol with examples. PHP_EOL is a predefined constant in PHP and represents an… Read More
This Laravel tutorial helps to understand table Relationships using Elequonte ORM. We'll explore laravel table Relationships usage and best practices… Read More
We'll explore different join methods of Laravel eloquent with examples. The join helps to fetch the data from multiple database… Read More
in this Laravel tutorial, We'll explore valet, which is a development environment for macOS minimalists. It's a lightweight Laravel development… Read More
I'll go through how to use soft delete in Laravel 10 in this post. The soft deletes are a method… Read More
View Comments
where we get openid.php
you can download here.
https://github.com/openid/php-openid
Hello Parwez,
Sorry , But its not working ... can you provide the complete zip file for this project .
Thanx
ok, i ll share with you.
how to get profile image
for which? each have different option to get image
would you share zip of project
sorry, i do not have code right now