我正在尝试使用Yahoo OpenID建立网站。
一切正常,直到我注销然后再次登录。
在我的sql数据库中,我得到重复的结果。仅散列被更改。看来$ sql = $ db-> query(“ SELECT * FROM users
WHERE steamid
='”。$ steamid。“'”);找不到带有SteamID的任何用户,它将在数据库中创建一个新条目。
我也用Steam尝试过,并且可以正常工作。使用Yahoo,我的电子邮件地址(此处为$ steamid)和名称(此处为$ name)得到重复的结果。哈希值是不同的。
case 'login':
include 'openid.php';
try
{
$openid = new LightOpenID('http://'.$_SERVER['SERVER_NAME'].'/');
if (!$openid->mode) {
$openid->identity = 'https://me.yahoo.com/a/6eqERecwyZfHsDm6VBa7H2uWNu3W5.UvCw--'; //http://steamcommunity.com/openid/
$openid->required = array(
'contact/email',
'namePerson',
);
header('Location: '.$openid->authUrl());
} elseif ($openid->mode == 'cancel') {
echo '';
} else {
if ($openid->validate()) {
//$id = $openid->identity;
//$ptn = "/^http:\/\/steamcommunity\.com\/openid\/id\/(7[0-9]{15,25}+)$/";
//preg_match($ptn, $id, $matches);
//$url = "http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=78DC279A43117B222DDEE0FCCCAD38FD&steamids=$matches[1]";
//$json_object = file_get_contents($url);
//$json_decoded = json_decode($json_object);
//foreach ($json_decoded->response->players as $player) {
$data = $openid->getAttributes();
$steamid = $data['contact/email'];
$name = $data['namePerson'];
//$avatar = $player->avatar;
//}
$hash = md5($steamid . time() . rand(1, 50));
$sql = $db->query("SELECT * FROM `users` WHERE `steamid` = '" . $steamid . "'");
$row = $sql->fetchAll(PDO::FETCH_ASSOC);
if (count($row) == 0) {
$db->exec("INSERT INTO `users` (`hash`, `steamid`, `name`) VALUES ('" . $hash . "', '" . $steamid . "', " . $db->quote($name) . ")");
} else {
$db->exec("UPDATE `users` SET `hash` = '" . $hash . "', `name` = " . $db->quote($name) . "' WHERE `steamid` = '" . $steamid . "'");
}
setcookie('hash', $hash, time() + 3600 * 24 * 7, '/');
header('Location: http://45.55.69.74/');
}
}
} catch (ErrorException $e) {
exit($e->getMessage());
}
break;
最佳答案
问题在于数据库中的Steamid长度较小。每次它检查整个Steamid是否与较小的Steamid相同。