1
我正在嘗試使用Yahoo OpenID創建Webiste。 一切工作正常,直到我註銷,然後再次登錄。 在我的sql數據庫中,我得到了重複的結果。只有散列被改變。看來$ sql = $ db-> query(「SELECT * FROM users
WHERE steamid
='」。$ steamid。「'」);用steamid找不到任何用戶,它會在db中創建一個新條目。 我也用Steam試過了,它工作正常。通過雅虎,我的電子郵件地址(這裏是$ steamid)和名稱(這裏是$ name)會得到重複的結果。哈希是不同的。OpenID在數據庫中的重複結果
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;
你爲什麼要做一個fetchAll? YOu可以改爲執行'$ sql-> rowCount()'。強制php和db檢索數據並將其格式化爲一個php數組沒有意義,所有這些都可以用來計算有多少個數組條目,然後將其全部丟棄。現在你很容易受到[sql注入攻擊](http://bobby-tables.com) –
蒸汽應該有一個唯一的索引 – e4c5
@Marc B我仍然在數據庫中得到重複的結果。只有散列被改變。 – Grizzlly