0

我目前正在实施并同时学习 OpenId 的使用。具体使用lightopenid。它正在工作,但我希望需要登录的用户在访问 URL www.example.com/login 时自动重定向到登录页面。下面的示例让用户单击一个按钮,然后将用户重定向到登录页面。如何使用 url www.example.com/login 自动将用户重定向到开放 ID 登录页面?

# Logging in with Google accounts requires setting special identity, so this example shows how to do it.
require 'openid.php';
try {
    # Change 'localhost' to your domain name.
    $openid = new LightOpenID('localhost');
    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();
}
4

1 回答 1

0

只需在您的唱歌页面中使用它

<?php // index.php
require_once 'openid.php';
$openid = new LightOpenID("www.example.com");
$openid->identity = 'https://www.google.com/accounts/o8/id';
$openid->returnUrl = 'http://www.example.com/login';
header('Location: ' . $openid->authUrl());
?>
于 2014-05-08T14:43:38.133 回答