2011-02-02 386 views
2

我在我的站点中实现了登录。我想实现登录有点如何在stackoverflow中完成。但只有一个选项的Gmail。 1)用户必须选择登录类型的Gmail 2)他必须输入自己的Gmail用户名和密码 3)他必须redirecred回到现场使用Gmail登录网站

我在这..Any帮助PLZ很新

+0

这个环节上其名为OpenID的外观http://technofriends.in/2008/11/10/what-is-openid-and-how-to-use-your-gmail-account-as-openid/ – 2011-02-02 12:00:28

回答

5

这是很容易与LightOpenID完成。他们有an example这个用例。

<?php 
# Logging in with Google accounts requires setting special identity, so this example shows how to do it. 
require 'openid.php'; 
try { 
    $openid = new LightOpenID; 
    if(!$openid->mode) { 
     if(isset($_GET['login'])) { 
      $openid->identity = 'https://www.google.com/accounts/o8/id'; 
      header('Location: ' . $openid->authUrl()); 
     } 
?> 
<form action="?login" method="post"> 
    <button>Login with Google</button> 
</form> 
<?php 
    } elseif($openid->mode == 'cancel') { 
     echo 'User has canceled authentication!'; 
    } else { 
     echo 'User ' . ($openid->validate() ? $openid->identity . ' has ' : 'has not ') . 'logged in.'; 
    } 
} catch(ErrorException $e) { 
    echo $e->getMessage(); 
} 

为了让你和运行是非常简单(我假设像* nix的系统):

  • 我已经www文件夹映射到我的服务器。
  • 我假设你有在localhost上运行的服务器。
  • 我假设你已经安装了google-chrome。

[email protected]:~/www$ wget http://gitorious.org/lightopenid/lightopenid/archive-tarball/master 
--2011-02-02 13:21:30-- http://gitorious.org/lightopenid/lightopenid/archive-tarball/master 
Resolving gitorious.org... 87.238.52.168 
Connecting to gitorious.org|87.238.52.168|:80... connected. 
HTTP request sent, awaiting response... 200 OK 
Length: 17104 (17K) [application/x-gzip] 
Saving to: `master' 

100%[======================================>] 17,104  --.-K/s in 0.04s 

2011-02-02 13:21:30 (386 KB/s) - `master' saved [17104/17104] 

[email protected]:~/www$ tar xfz master 
[email protected]:~/www$ google-chrome http://localhost/lightopenid-lightopenid/example-google.php 
Created new window in existing browser session. 
+0

非常感谢......你可以举个简单的例子... – 2011-02-02 12:09:14

+0

这是一个完整的简单例子;)。当你下载tarball时,你可以运行这个例子=> http://gitorious.org/lightopenid/lightopenid/archive-tarball/master – Alfred 2011-02-02 12:17:33