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.
How to Connect Google with OpenId
Step 1:
Download auth file from below url.
Download OpenID
Step 2:
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=""> <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>
Final Result :
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(); ?>
Other OpenId Options
There are other account providers also available,You just have to change the url $openid->identity()
function by below url:
- WordPress:
http://yourblog.wordpress.com
- Google:
https://www.google.com/accounts/o8/id
- Google profile:
http://www.google.com/profiles/\~YOURUSERNAME
- Yahoo:
https://me.yahoo.com
- LiveJournal:
http://www.livejournal.com/openid/server.bml
- AOL:
https://www.aol.com
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