我已经使用lightopenid实现了一个Google open-id登录 - 注册系统工作正常,我想添加一项功能,要求用户只注册一次以允许访问他们的信息,然后我将该信息存储在数据库中登录后记。
一旦我获得了他们的信息(身份,姓名,电子邮件),我将他们存储在数据库中,通过相同的流程将其记录在后面,除了跳过用户一次又一次地授予对他们信息的访问权。
即当用户注册并授予对该信息的访问权限时,下一次用户不必每次登录时都授予访问权限。
实现它我在尝试登录时检查他们在数据库中的身份,如果存在身份然后登录他们而不在lightopenid中询问信息,如果身份不是他们要求他们的信息将其存储在数据库中以供稍后使用登录使用。
我可以检查他们在数据库中的身份,但是如果身份不是他们的那么卡在部分中然后如何询问他们的信息,因为我在登录时没有请求lightopenid中的信息。
存储信息的代码一次。(SignUp)
$openid = new LightOpenID('localhost');
if(!$openid->mode) {
if(isset($_GET['login'])) {
$openid->identity = 'https://www.google.com/accounts/o8/id';
$openid->required = array('namePerson/first', 'namePerson/last', 'contact/email');
header('Location: ' . $openid->authUrl());
}
}
if($openid->validate()) {
require_once('../connect.php');
$identity = $openid -> identity;
$info = $openid->getAttributes();
$username = $info['namePerson/first'].'.'.$info['namePerson/last'];
$open_id = explode('=', $identity);
$identity_hash = $open_id[1];
$email = $info['contact/email'];
$query = "INSERT INTO user_login (username, identity_hash, email) VALUES ('$username', '$identity_hash', '$email')";
$create_user = mysqli_query($connection, $query) or trigger_error(mysqli_error($connection), E_USER_ERROR);
}
检查身份的代码。(登录)
if(!$openid->mode) {
if(isset($_GET['login'])) {
$openid->identity = 'https://www.google.com/accounts/o8/id';
header('Location: ' . $openid->authUrl());
}
}
if($openid->validate()) {
require_once('../connect.php');
$identity = $openid -> identity;
$open_id = explode('=', $identity);
$identity_hash = $open_id[1];
$query = "SELECT * FROM user_login WHERE identity_hash='$identity_hash'";
$result = mysqli_query($ulconnection, $query) or trigger_error(mysqli_connect_error(), E_USER_ERROR);
if($result){
$row = mysqli_fetch_assoc($result);
$username = $row['username'];
$email = $row['email'];
echo $username.'<br />';
echo $email.'<br />';
}
else{
// how to ask for info here.
}
}
请参阅并建议任何可行的方法。
感谢。
答案 0 :(得分:0)
我这样做了。
if($result){
$row = mysqli_fetch_assoc($result);
$username = $row['username'];
$email = $row['email'];
echo $username.'<br />';
echo $email.'<br />';
}
else{
header("Location: signup.php?login");
}
希望这也有助于其他人。