且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用Gmail登录网站

更新时间:2023-12-04 10:48:10

使用 LightOpenID 非常容易完成.考虑到该用例,他们有一个示例.

This is very easy to accomplish with LightOpenID. They have an example available with that use case in mind.

<?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像系统一样):

To get you up and running is really simple(I assume *nix like system):

  • 我有www文件夹映射到我的服务器.
  • 我假设您有在本地主机上运行的服务器.
  • 我认为您已经安装了google-chrome.
  • I have www folder mapped to my server.
  • I assume you have server it running on localhost.
  • I assume you have google-chrome installed.
alfred@alfred-laptop:~/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]

alfred@alfred-laptop:~/www$ tar xfz master 
alfred@alfred-laptop:~/www$ google-chrome http://localhost/lightopenid-lightopenid/example-google.php
Created new window in existing browser session.