MySQL脚本检索Steam ID,没有别的

时间:2017-01-30 14:30:15

标签: php mysql steam

我的网络Steam身份验证存在问题。如您所知,Steam提供了一个脚本,允许人们通过Steam数据库在您的站点上进行连接。我的问题是我的代码只在数据库中插入Steam ID而不是名称&头像。 我的代码:

if (isset($_GET['login'])){
require 'db.php';
require 'openid.php';
require 'userInfo.php';
try {
    require 'SteamConfig.php';

    $openid = new LightOpenID($steamauth['domainname']);

    if(!$openid->mode) {
        $openid->identity = 'http://steamcommunity.com/openid';
        header('Location: ' . $openid->authUrl());
    } elseif ($openid->mode == 'cancel') {
        echo 'User has canceled authentication!';
    } else {
        if($openid->validate()) { 
            $id = $openid->identity;
            $ptn = "/^http:\/\/steamcommunity\.com\/openid\/id\/(7[0-9]{15,25}+)$/";
            preg_match($ptn, $id, $matches);

            $_SESSION['steamid'] = $matches[1];

                $sql_fetch_id = "SELECT * FROM member WHERE steamid = '".$_SESSION['steamid']."'";
                $query_id = mysqli_query($db, $sql_fetch_id);

                if (mysqli_num_rows($query_id) == 0) {
                    $sql_steam = "INSERT INTO member (name, steamid, avatar) VALUES  ('".$_SESSION['personaname']."', '".$_SESSION['steamid']."', '".$_SESSION['avatar']."')";
                    mysqli_query($db, $sql_steam);
                }

            if (!headers_sent()) {
                header('Location: '.$steamauth['loginpage']);
                exit;
            } else {
                ?>
                <script type="text/javascript">
                    window.location.href="<?=$steamauth['loginpage']?>";
                </script>
                <noscript>
                    <meta http-   equiv="refresh" content="0;url=<?=$steamauth['loginpage']?>" />
                </noscript>
                <?php
                exit;
            }

            } else {
            echo "User is not logged in.\n";
        }
    }
} catch(ErrorException $e) {
    echo $e->getMessage();
}
 }

截图 screenshot

1 个答案:

答案 0 :(得分:0)

查看var_dump($_SESSION)的输出(应该在问题中),好像您实际上没有正确引用会话的密钥。

使用以下代码:

$sql_steam = "INSERT INTO member (name, steamid, avatar) VALUES  ('".$_SESSION['personaname']."', '".$_SESSION['steamid']."', '".$_SESSION['avatar']."')";

您引用$_SESSION['personaname'],但会话中仅提供['steam_personaname']。所以你引用了那些不存在的东西。

所以你应该使用:

$sql_steam = "INSERT INTO member (name, steamid, avatar) VALUES  ('".$_SESSION['steam_personaname']."', '".$_SESSION['steamid']."', '".$_SESSION['steam_avatarfull']."')";