OpenID重复结果存储在数据库中

时间:2016-09-26 20:03:53

标签: php mysql database openid lightopenid

我正在尝试使用Yahoo OpenID建立一个网站。 一切正常,直到我退出然后再次登录。 在我的SQL数据库中,我得到了重复的结果。只更改了哈希值。似乎$ sql = $ db-> query(" SELECT * FROM users WHERE steamid ='"。$ steamid。"&# 39;&#34);无法找到任何使用steamid的用户在db中创建一个新条目。 我也尝试使用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;

1 个答案:

答案 0 :(得分:0)

问题是数据库中的蒸汽长度较小。每次检查整个蒸汽都是否与较小的蒸汽相同。