我目前正在实施并同时学习OpenId的使用。特别是使用lightopenid。它正在运行,但我希望在访问网址www.example.com/login时,需要登录的用户会自动重定向到登录页面。以下示例让用户单击按钮,然后将用户重定向到登录页面。如何使用网址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();
}
答案 0 :(得分: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());
?>