Steam 开放 ID API

Steam OpenID API

我想为我的站点设置 Steam 登录。我唯一想从 Steam 获得的是登录,获取他的用户名并为该用户启动 session。我遵循了 YouTube 上的教程,基本上完成了该视频中的所有操作,但是当我通过 Steam 按登录时,我得到:example.com/(()%7D。 代码:

    <?php
   include "includes/apikey.php";
 include "includes/openid.php";

ob_start();

$OpenID = new LightOpenID("http://astral-gaming.com");

session_start();

?>

这是我的header。此外,我将此 php 放在文档的中间(因为我希望登录出现在所有导航栏元素之后:

<?php 

if(!$OpenID->mode) {

if(isset($_GET['login'])) {
 $OpenID->identity = "http://steamcommunity.com/openid";
 header("Location: ($OpenID->authUrl()}");
}

if(!isset($_SESSION['T2SteamAuth'])) {
 $login = "<li><a href =\"?login\"><img src=\"http://steamcommunity-        a.akamaihd.net/public/images/signinthroughsteam/sits_small.png\"/></a></li>";
 }
} elseif($OpenID->mode == "cancel"){

} else {

if(!isset($_SESSION['TF2SteamAuth'])) {
$_SESSION['TF2SteamAuth'] = $OpenID->validate() ? $OpenID->identity: null;
$_SESSION['TF2SteamID64'] =       str_replace("http://steamcommunity.com/openid/id/", "",     $_SESSION['TF2SteamAuth']);

if($_SESSION['TF2SteamAuth'] !== null) {

$Steam64 = str_replace("http:// (ignore     space)steamcommunity.com/openid/id/", "", $_SESSION['TF2SteamAuth']);
$profile = file_get_contents("http:// (ignore space) api.steampowered.com/IsteamUser/GetPlayerSummaries/v0002/?key={$api}&steamids=($Steam64)");
$buffer = fopen("cache/{$steam64}.json", "w+");
fwrite($buffer, $profile);
fclose($buffer);


}

header("Location: index.php");

}

}
if(isset($_SESSION['T2SteamAuth'])) {

$login = "<li><a href =\"?logout\">Steam LogOut</a></li>";
}

if(isset($_GET['logout'])) {

unset($_SESSION['T2SteamAuth']);
unset($_SESSION['T2SteamAuth']);
header("Location: index.php");


}

您的代码中到处都有 bad/mismatched bracketing/bracing:

 header("Location: ($OpenID->authUrl()}");
                   ^-- this should probably be a {?