2011-02-02 383 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