2013-12-09 608 views
1

我正在使用steam open id來允許用戶登錄到我的網站。這是我現在擁有的。只是一個不是我從一個教程得到這個,並改變它以符合我的需求。Steam Openid登錄

<?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,然後以我的代碼單獨登錄。我想讓這個代碼允許用戶登錄到論壇。任何幫助都會很棒。謝謝

回答

0

對於header()命令工作,HTML之前必須輸出。即使是最小的空間也可能阻止它重新定向。

我知道這是一個遲到的答案,但我希望它能幫助別人。