1

我正在尝试使用 Yahoo OpenID 创建一个网站。一切正常,直到我注销然后再次登录。在我的 sql 数据库中,我得到重复的结果。仅更改哈希。似乎 $sql = $db->query("SELECT * FROM usersWHERE 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;
4

1 回答 1

0

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

于 2017-06-16T11:06:31.723 回答