Steam Openid登录

时间:2013-12-09 23:49:43

标签: php wordpress openid steam

我正在使用steam open id来允许用户登录我的网站。这就是我现在拥有的。只是一个不是我从教程中得到这个并改变它以符合我的需要。

<?php
include "apikey.php";
include "OpenID.php";
   $link = mysql_connect('', '', '', ' ');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';



$OpenID = new LightOpenID("MyWebsite");

session_start();

if(!$OpenID->mode) {

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

        $OpenID->identity = "http://steamcommunity.com/openid";
        header("Location: {$OpenID->authUrl()}");
    }

    if(!isset($_SESSION['T2SteamAuth'])){
         $login = print ('<form action="?login" method="post">
    <input type="image" src="http://cdn.steamcommunity.com/public/images/signinthroughsteam/sits_large_border.png"/>
    </form>');
    }

}   elseif($OpenID->mode == "cancel") {
  echo "canceled";
}   else {
     if(!isset($_SESSION['T2SteamAuth'])) {

         $_SESSION['T2SteamAuth'] = $OpenID->validate() ? $OpenID->identity : null;
         $_SESSION['T2SteamID64'] = str_replace("http://steamcommunity.com/openid/id", "", $_SESSION['T2SteamAuth']);


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

             $Steam64 = str_replace("http://steamcommunity.com/openid/id", "", $_SESSION['T2SteamAuth']);
             $profile = file_get_contents("http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key={$api}&steamids={$Steam64}"); 
             $buffer = fopen("cache/{Steam64}.json". "w+");
             fwrite($buffer, $profile);
             fclose($buffer);
          }
          header("Location: login3.php");
     }

}
    if(isset($_SESSION['T2SteamAuth'])) {
    $Steam64id = $_SESSION['T2SteamAuth'];
    print($Steam64id);
$sql = "INSERT INTO ``.`` (`id`) VALUES ('$Steam64id')";
mysql_query($sql, $link);
mysql_close($link);
print('<form action = "?logout" method="post"><button title="logout"          name="logout">Logout</button></form>');
}
if(isset($_GET['logout'])) {
    unset($_SESSION['T2SteamAuth']);
    unset($_SESSION['T2SteamID64']);
    header("Location: login3.php");
}   



?>

此代码允许用户登录我的网站,并将其ID发送到我的数据库。我想要做的是允许这些用户使用论坛。我下载了一个论坛插件并打开了id,但由于某些原因,我的代码不允许用户使用我的论坛,我不知道为什么。为了让用户使用我的论坛,他们必须转到wp-login.php并输入https://steamcommunity.com/openid/login,然后以我的代码分开登录。我想让这段代码允许用户登录论坛。任何帮助都会很棒。感谢

1 个答案:

答案 0 :(得分:0)

要使header()命令起作用,必须先输出HTML。即使是最小的空间也可能阻止它重定向。

我知道这是一个迟到的答案,但我希望它会帮助别人。