如何实现openid google、yahoo等

如何实现openid google、yahoo等,openid,google-openid,openid-provider,openid-selector,Openid,Google Openid,Openid Provider,Openid Selector,我正在尝试实现OpenID,为此我下载并从中选择了Auth文件夹,将任何内容更改为localhost目录,并创建了index.php文件,其代码如下: <?php if (!isset($_POST['submit'])) { ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd">

我正在尝试实现OpenID,为此我下载并从中选择了Auth文件夹,将任何内容更改为localhost目录,并创建了index.php文件,其代码如下:

<?php
    if (!isset($_POST['submit'])) {
?>
        <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
        "DTD/xhtml1-transitional.dtd">
        <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
        <head>
        <title>OPENID TESTING</title>
        </head>
        <body>
        <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
            Sign in with your OpenID: <br/>
            <input type="text" name="id" size="30" />
            <br />
            <input type="submit" name="submit" value="Log In" />
        </form>
        </body>
        </html>
<?php
    } else {

        // check for form input
        if (trim($_POST['id'] == '')) {
            die("ERROR: Please enter a valid OpenID.");
        }

        // include files
        require_once "Auth/OpenID/Consumer.php";
        require_once "Auth/OpenID/FileStore.php";

        // start session (needed for YADIS)
        session_start();

        // create file storage area for OpenID data
        $store = new Auth_OpenID_FileStore('./oid_store');

        // create OpenID consumer
        $consumer = new Auth_OpenID_Consumer($store);

        // begin sign-in process
        // create an authentication request to the OpenID provider

        $auth = $consumer->begin($_POST['id']);
        if (!$auth) {
            die("ERROR: Please enter a valid OpenID.");
        }

        // redirect to OpenID provider for authentication
        $url = $auth->redirectURL('http://localhost/', 'http://localhost/oid_return.php');
        header('Location: ' . $url);
    }
?>

OPENID测试

我使用PHP LightOpenID库()让用户能够使用他们的Google帐户登录我的网站。对于其他OpenID提供程序,您只需更改
$OpenID->identity
字段。它为我们处理所有的身份验证流程。你不必为代币之类的事操心

这里是我显示“使用谷歌登录”链接的页面:

如果要从用户检索更多信息,必须将它们添加到第一页的
$openid->required
。例如:

$openid->required = array(
  'contact/email',
  'namePerson/first',
  'namePerson/last'
);
如果用户接受,将允许您在第二页中获取他的名字和姓氏:

$name = $data['namePerson/first'] . " " . $data['namePerson/last'];

希望有帮助

我尝试添加“namePerson/first”,“namePerson/last”似乎与谷歌或雅虎都不起作用(我确实收到了电子邮件和其他值)。知道为什么吗?
$openid->required = array(
  'contact/email',
  'namePerson/first',
  'namePerson/last'
);
$name = $data['namePerson/first'] . " " . $data['namePerson/last'];