[英]Redirecting user to Login OpenID page
I am currently implementing and at the same time learning the use of OpenId. 我目前正在实施,同时学习OpenId的用法。 Specifically using lightopenid .
具体使用lightopenid 。 It is working but I would like users that are needing to login to be redirected automatically to the login page when accessing the url www.example.com/login.
它正在工作,但是我希望需要登录的用户在访问URL www.example.com/login时自动重定向到登录页面。 The example below has the user click on a button and then redirects the user to the login page.
下面的示例使用户单击按钮,然后将用户重定向到登录页面。 How can I redirect the user automatically with url www.example.com/login to the open ID login page?
如何使用网址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();
}
Just simple use this in your singin page 只需在您的singin页面中使用它
<?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());
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.