你好
几个小时前我已经下载了LightOpenID (http://gitorious.org/lightopenid),但仍然想不出如何让它工作。
我在test.php文件中保存了这个google示例
<?php
require '../lib/init.php';
require '../lib/openID/openid.php';
try {
if(!isset($_GET['openid_mode'])) {
if(isset($_GET['login'])) {
$openid = new LightOpenID;
$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($_GET['openid_mode'] == 'cancel') {
echo 'User has canceled authentication!';
} else {
$openid = new LightOpenID;
echo 'User ' . ($openid->validate() ? $openid->identity . ' has ' : 'has not ') . 'logged in.';
}
} catch(ErrorException $e) {
echo $e->getMessage();
}
echo '<pre>'.print_r($openid,true).'</pre>';
?>其中init.php是我的页面的init文件(常量、类、函数、db连接等等)。
运行这段代码后,我得到了标签为“使用谷歌登录”的按钮,并按了它。
echo '<pre>'.print_r($openid,true).'</pre>';提供有关$openid对象的一些信息
LightOpenID对象( returnUrl => http://kur.com/openid.php required => Array () 可选的=>阵列()标识:LightOpenID:私有=> https://www.google.com/accounts/o8/id claimed_id:LightOpenID:private => https://www.google.com/accounts/o8/id服务器:受保护的=> https://www.google.com/accounts/o8/ud版本:受保护的=> 2信任根:受保护的=> http://kur.com别名:受保护的=> identifier_select:protected => 1 ax:受保护的=> 1 sreg:受保护的=>数据:受保护的=>数组(登录存储) )
...nothing特别..。就这样..。
我花了很多时间在谷歌搜索教程,但却找不到。你能帮帮我吗。
如何登录用户?
从哪里我必须得到记录的用户信息(如用户名,邮件)?
我从来没有使用过开放的身份证,我很困惑.
提前感谢
发布于 2012-07-20 18:45:28
这个脚本现在在我的本地主机上正常工作,在我的笔记本电脑上运行apache,通过wifi连接到互联网。
有人告诉我,在创建域时,应该将域传递给新的LightOpenId对象。
$iniConfig是存储在文档根目录之外的parse_ini_file数组,我在这里存储所有重要变量。
在这种情况下
[openid]
domain='mydomain.com' 因此,我创建新对象并包括服务器所在的域:
$openid = new LightOpenID($iniConfig['openid']['domain']);我是这样写的,还没有检查它在没有域的情况下是否有效。
发布于 2010-10-22 16:48:32
如何登录用户?
在您的示例中,有一行显示了如何完成身份验证:
echo 'User ' . ($openid->validate() ? $openid->identity . ' has ' : 'has not ') . 'logged in.';如果$openid->validate()返回true,则意味着对声称为$openid->identity的用户进行身份验证。
如果将其与标准身份验证进行比较:
标准行政当局:
OpenID auth(与LightOpenID一起):
$openid->validate()validate()返回true,则对用户进行身份验证(使用$openid->identity),因此我们设置了一个cookie来记住他(或者您在成功登录时想要做的其他任何事情)。基本上,一旦您确认用户是他声称的那个人(即他已经通过身份验证),您就会像一个正常的auth一样进行下去。
通常,您必须将标识与会话id一起存储在某个地方。
从哪里我必须得到记录的用户信息(如用户名,邮件)?
用户名在$openid->identity中。但是,您可能希望使用昵称作为显示的名称。然而,获取昵称和电子邮件地址需要额外的配置。基本上,在调用$openid->authUrl()之前,您必须添加:
$openid->required = array('namePerson/friendly', 'contact/email');这一行将导致LightOpenID请求这些参数。您可以在axschema.org上看到其他参数的列表(OPs可能支持也可能不支持这些参数)。然后,在调用validate()之后,调用$openid->getAttributes()来获取这些值。它将返回所有可获得的参数,例如:
array(
[namePerson/friendly] => Mewp
[contact/email] => mewp@example.com
)但是,请注意,此列表可以包含其他参数,并且可能不包含所请求的参数。基本上,OP可以自由地返回它想要的任何东西,所以您需要为缺少一些价值做好准备。
发布于 2011-07-04 16:27:31
当用户在“示例-google.php”页面上单击“”按钮时,您将被重定向到google,如果用户接受请求,他将再次被重定向到您的页面,您只能获得用户的Openid。
但是,如果您想获得其他信息或更改OpenID,您可以这样做:
<?php
require 'openid.php';
try {
$openid = new LightOpenID;
if(!$openid->mode) {
if(isset($_GET['oidType'])) {
$oidType = $_GET['oidType'];
$openid = new LightOpenID;
if ($oidType==1)
{
$openid->identity = 'https://www.google.com/accounts/o8/id';
}
else
{
$openid->identity = 'https://me.yahoo.com ';
}
$openid->required = array(
'namePerson',
'namePerson/first',
'namePerson/last',
'contact/email',
);
$openid->returnUrl = 'http://www.yourdomain.com/login.php';
header('Location: ' . $openid->authUrl());
}
?>
<a href="?oidType=1">Login with Google</a>
<a href="?oidType=2">Login with Yahoo</a>
<?php
} elseif($openid->mode == 'cancel') {
echo 'User has canceled authentication!';
}
} elseif($openid->validate()) {
$openid_identity = $openid->identity;
$data = $openid->getAttributes();
$email = $data['contact/email'];
$namePerson = $data['namePerson'];
$first = $data['namePerson/first'];
$last = $data['namePerson/last'];
echo "Openid:$identitystr <br>";
echo "Email : $email <br>";
echo "namePerson : $namePerson <br>";
echo "first : $first <br>";
echo "last : $last <br>";
} else {
echo "The user has not logged in";
}
} catch(ErrorException $e) {
echo $e->getMessage();
}https://stackoverflow.com/questions/3995011
复制相似问题