Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/295.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 将用户重定向到登录OpenID页_Php_Openid_Lightopenid - Fatal编程技术网

Php 将用户重定向到登录OpenID页

Php 将用户重定向到登录OpenID页,php,openid,lightopenid,Php,Openid,Lightopenid,我目前正在实现并同时学习OpenId的使用。具体使用。它正在工作,但我希望需要登录的用户在访问url www.example.com/login时自动重定向到登录页面。下面的示例让用户单击按钮,然后将用户重定向到登录页面。如何使用url www.example.com/login将用户自动重定向到open ID登录页面 # Logging in with Google accounts requires setting special identity, so this example show

我目前正在实现并同时学习OpenId的使用。具体使用。它正在工作,但我希望需要登录的用户在访问url www.example.com/login时自动重定向到登录页面。下面的示例让用户单击按钮,然后将用户重定向到登录页面。如何使用url www.example.com/login将用户自动重定向到open 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();
}
#使用谷歌账户登录需要设置特殊身份,因此本例展示了如何进行设置。
需要“openid.php”;
试一试{
#将“localhost”更改为您的域名。
$openid=new LightOpenID('localhost');
如果(!$openid->模式){
如果(isset($\u GET['login'])){
$openid->identity=https://www.google.com/accounts/o8/id';
标题('Location:'。$openid->authUrl());
}
?>
使用谷歌登录

只需在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());
?>