[英]How to use open id as login system
I want to try to use open id as login system on the site that I am going to make. 我想尝试在我要制作的网站上使用open id作为登录系统。 I've check out this site, and I'm not pretty sure how this all works and how to make it work.
我查看了这个网站,我不太确定这一切是如何工作的,以及如何使它工作。 http://remysharp.com/2007/12/21/how-to-integrate-openid-as-your-login-system/
http://remysharp.com/2007/12/21/how-to-integrate-openid-as-your-login-system/
What is clear right now is that open id uses urls instead of passwords. 现在很清楚的是,open id使用url而不是密码。 Can you give me some links to help me get started with this, Do I need to know advanced php to make this work for me.
你能给我一些链接来帮助我开始这个吗?我需要知道高级的PHP才能让我的工作能够得到帮助。 I only know the basics of php.
我只知道php的基础知识。
Thanks to some other comment on Stackoverflow.com I came to learn about LightOpenId . 感谢Stackoverflow.com上的其他评论,我开始了解LightOpenId 。 It is really easy to use.
它真的很容易使用。
The example code just works(without any configuration): 示例代码正常工作(没有任何配置):
<?php
require 'openid.php';
try {
$openid = new LightOpenID;
if(!$openid->mode) {
if(isset($_POST['openid_identifier'])) {
$openid->identity = $_POST['openid_identifier'];
header('Location: ' . $openid->authUrl());
}
?>
<form action="" method="post">
OpenID: <input type="text" name="openid_identifier" /> <button>Submit</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();
}
Using google as openid provider . 使用谷歌作为openid提供商 。
<?php
# Logging in with Google accounts requires setting special identity, so this example shows how to do it.
require 'openid.php';
try {
$openid = new LightOpenID;
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();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.