我想尝试在我要制作的网站上使用open id作为登录系统.我查看了这个网站,我不太确定这一切是如何工作的,以及如何使它工作. http://remysharp.com/2007/12/21/how-to-integrate-openid-as-your-login-system/
现在很清楚的是,open id使用url而不是密码.你能给我一些链接来帮助我开始这个吗?我需要知道高级的PHP才能让我的工作能够得到帮助.我只知道php的基础知识.
Alf*_*red 11
感谢Stackoverflow.com上的其他评论,我开始了解LightOpenId.它真的很容易使用.
该示例代码只是工作(无需任何配置):
<?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();
}
Run Code Online (Sandbox Code Playgroud)
<?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();
}
Run Code Online (Sandbox Code Playgroud)