使用Gmail登录网站

sid*_*ant 2 php openid

我在我的网站中实现登录.我想在stackoverflow.But中实现登录,只有一个选项gmail.1)用户必须选择登录类型作为gmail 2)他必须输入他的gmail用户名和密码3)他必须重定向回网站

我是非常新的..任何帮助PLZ

Alf*_*red 5

使用LightOpenID非常容易实现.他们有一个示例可用于该用例.

<?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();
}
Run Code Online (Sandbox Code Playgroud)

让你启动并运行非常简单(我假设*nix喜欢系统):

  • 我有www文件夹映射到我的服务器.
  • 我假设你有服务器在localhost上运行.
  • 我假设你安装了谷歌浏览器.

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.
Run Code Online (Sandbox Code Playgroud)