im新的打开id,但我仍然尝试在我的网站上集成开放id。我使用雅虎提供商登录我的网站。可以帮助我获取雅虎邮件ID等用户信息,名字,姓氏。

我已经从谷歌提供的网站上获取以下代码,我将提供商更改为雅虎

我尝试过的代码:

<?php
# 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://me.yahoo.com';
header('Location: ' . $openid->authUrl());
}
?>
<form action="?login" method="post">
<button>Login with Yahoo</button>
</form>
<?php
} elseif($openid->mode == 'cancel') {
echo 'User has canceled authentication!';
} else {
echo 'User ' . ($openid->validate() ? $openid->identity . ' has ' : 'has not ') . 'logged in.';
print_r($openid->ax_to_sreg);
}
} catch(ErrorException $e) {
echo $e->getMessage();
}
.

loggin im熄灭如下:

User https://open.login.yahooapis.com/openidx20/user_profile/XXXX has logged in.
.

上述URL的使用是什么?如何获取用户信息?

有帮助吗?

解决方案

在googling后找到了我的解决方案。现在我能够获取登录用户的电子邮件

以下是修改后的代码:

<?php


require 'openid.php';

try
{
    # Change 'localhost' to your domain name.
    $openid = new LightOpenID($_SERVER['HTTP_HOST']);

    //Not already logged in
    if(!$openid->mode)
    {

        //do the login
        if(isset($_GET['login']))
        {
            //The google openid url
            $openid->identity = 'https://me.yahoo.com';

            //Get additional google account information about the user , name , email , country
            $openid->required = array('contact/email' , 'namePerson/first' , 'namePerson/last' , 'pref/language' , 'contact/country/home');

            //start discovery
            header('Location: ' . $openid->authUrl());
        }
        else
        {
            //print the login form
            login_form();
        }

    }

    else if($openid->mode == 'cancel')
    {
        echo 'User has canceled authentication!';
        //redirect back to login page ??
    }

    //Echo login information by default
    else
    {
        if($openid->validate())
        {
            //User logged in
            $d = $openid->getAttributes();

            $first_name = $d['namePerson/first'];
            $last_name = $d['namePerson/last'];
            $email = $d['contact/email'];
            $language_code = $d['pref/language'];
            $country_code = $d['contact/country/home'];

            $data = array(
                'first_name' => $first_name ,
                'last_name' => $last_name ,
                'email' => $email ,
            );

            //now signup/login the user.
            print_r($data);
        }
        else
        {
            //user is not logged in
        }
    }
}

catch(ErrorException $e)
{
    echo $e->getMessage();
}

/*
    This function will print the login form with the button
*/
function login_form()
{
?>
<a href="?login">Login with Yahoo</a>
<?php
}
.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top