【问题标题】:Steam Authentication SessionSteam 身份验证会话
【发布时间】:2017-06-16 00:23:06
【问题描述】:

如您所知,steam 提供了一个脚本,允许人们通过 steam 数据库连接到您的网站。 如果我刷新页面,我想我不必再次登录。但是使用 steamapi 我不知道该怎么做。

我的代码:

<?php
require 'includes/lightopenid/openid.php';
include_once("db.php");

$_STEAMAPI = "MYAPI";
try {
    $openid = new LightOpenID('http://test/dev1/index.php?id=1');
    if(!$openid->mode) {
        if(isset($_GET['login'])) {
            $openid->identity = 'http://steamcommunity.com/openid/?l=english';
            header('Location: ' . $openid->authUrl());
        } else {

            echo "<form action='?login' method='post'>";
            echo "<input type='image' src='http://cdn.steamcommunity.com/public/images/signinthroughsteam/sits_small.png'>";
            echo "</form>";
        }
    } 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);

            $url = "http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=$_STEAMAPI&steamids=$matches[1]";
            $json_object= file_get_contents($url);
            $json_decoded = json_decode($json_object);

            foreach ($json_decoded->response->players as $player)
            {
                $sql_fetch_id = "SELECT * FROM member WHERE steamid = '$player->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  ('$player->personaname', '$player->steamid', '$player->avatar')";
                    mysqli_query($db, $sql_steam);
                }
                   echo "Welcome back <b>" . $player->personaname . "</br>";
            }
        } else {
            echo "User is not logged in.\n";
        }
    }
} catch(ErrorException $e) {
    echo $e->getMessage();
}
?>

【问题讨论】:

    标签: php mysql openid steam lightopenid


    【解决方案1】:

    一般方法是设置session - 在PHP 中,您可以使用$_SESSION 来存储此信息。这允许您为每个用户存储持久的服务器端数据。

    检索到用户的 SteamID64 后,将其保存在 $_SESSION 中,例如:

    $_SESSION['steamid'] = $someVal;

    您可以检查它是否在每个后续请求中设置并采取相应措施。

    您可以在此处查看完整示例:https://github.com/SmItH197/SteamAuthentication

    (免责声明:我不是该库的作者。)

    【讨论】:

      猜你喜欢
      • 2013-09-11
      • 2015-05-15
      • 1970-01-01
      • 1970-01-01
      • 2016-04-24
      • 1970-01-01
      • 2019-10-28
      • 2013-04-03
      相关资源
      最近更新 更多