我目前正在实施并同时学习 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();
}