2015-06-28 48 views
0

我已經使用本教程來實現我創建的網站的蒸汽登錄:https://github.com/SmItH197/SteamAuthentication/blob/f47fc78056081d6a83d277ae447c5386dc0909fc/README.md。問題是,當我登錄時,它不顯示任何信息,只有註銷按鈕。這是我正在處理的代碼。無法通過登錄獲取Steam API來顯示頭像

if(isset($_SESSION['steamid'])){ 

    include("settings.php"); 
    if (empty($_SESSION['steam_uptodate']) or $_SESSION['steam_uptodate'] == false or empty($_SESSION['steam_personaname'])) { 
     //We mute alerts from the following line because we do not want to give away our API key in case file_get_contents() throws a warning. 
     @ $url = file_get_contents("http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=".$steamauth['apikey']."&steamids=".$_SESSION['steamid']); 
     if($url === FALSE) { die('Error: failed to fetch content form Steam. It may be down. Please, try again later.'); } 
     $content = json_decode($url, true); 
     $_SESSION['steam_steamid'] = $content['response']['players'][0]['steamid']; 
     $_SESSION['steam_communityvisibilitystate'] = $content['response']['players'][0]['communityvisibilitystate']; 
     $_SESSION['steam_profilestate'] = $content['response']['players'][0]['profilestate']; 
     $_SESSION['steam_personaname'] = $content['response']['players'][0]['personaname']; 
     $_SESSION['steam_lastlogoff'] = $content['response']['players'][0]['lastlogoff']; 
     $_SESSION['steam_profileurl'] = $content['response']['players'][0]['profileurl']; 
     $_SESSION['steam_avatar'] = $content['response']['players'][0]['avatar']; 
     $_SESSION['steam_avatarmedium'] = $content['response']['players'][0]['avatarmedium']; 
     $_SESSION['steam_avatarfull'] = $content['response']['players'][0]['avatarfull']; 
     $_SESSION['steam_personastate'] = $content['response']['players'][0]['personastate']; 
     if (isset($content['response']['players'][0]['realname'])) { 
       $_SESSION['steam_realname'] = $content['response']['players'][0]['realname']; 
      } else { 
       $_SESSION['steam_realname'] = "Real name not given"; 
     } 
     $_SESSION['steam_primaryclanid'] = $content['response']['players'][0]['primaryclanid']; 
     $_SESSION['steam_timecreated'] = $content['response']['players'][0]['timecreated']; 
     $_SESSION['steam_uptodate'] = true; 
    } 

    $steamprofile['steamid'] = $_SESSION['steam_steamid']; 
    $steamprofile['communityvisibilitystate'] = $_SESSION['steam_communityvisibilitystate']; 
    $steamprofile['profilestate'] = $_SESSION['steam_profilestate']; 
    $steamprofile['personaname'] = $_SESSION['steam_personaname']; 
    $steamprofile['lastlogoff'] = $_SESSION['steam_lastlogoff']; 
    $steamprofile['profileurl'] = $_SESSION['steam_profileurl']; 
    $steamprofile['avatar'] = $_SESSION['steam_avatar']; 
    $steamprofile['avatarmedium'] = $_SESSION['steam_avatarmedium']; 
    $steamprofile['avatarfull'] = $_SESSION['steam_avatarfull']; 
    $steamprofile['personastate'] = $_SESSION['steam_personastate']; 
    $steamprofile['realname'] = $_SESSION['steam_realname']; 
    $steamprofile['primaryclanid'] = $_SESSION['steam_primaryclanid']; 
    $steamprofile['timecreated'] = $_SESSION['steam_timecreated']; 

} 

我希望發生的是,當有人登錄,其中在按鈕的跡象是,我想說明的蒸汽名稱,以及無論誰在簽署的化身。

+0

你沒有在你的程序中迴應或打印一件東西。 – Digits

+0

關於使用'@'的那一行:如果用戶可以看到PHP輸出的警告,則暴露您的API密鑰應該是您最擔心的問題。 – SeinopSys

回答

0

你看了文檔?要顯示頭像,請執行下列操作:

$steamprofile['avatar'] // 32x32 version of avatar 
$steamprofile['avatarmedium'] // 64x64 version of avatar 
$steamprofile['avatarfull'] // 184x184 version of avatar 

要顯示的蒸汽用戶名,請執行下列操作:

$steamprofile['personaname'] 

這一切都寫在README.md文件底部。

編輯:如果你想顯示的圖像,做這樣的事情:

echo '<img src="' . $steamprofile['avatar'] . '" />'; 

,將放在從$steamprofile['avatar']圖像URL爲<img>元素。

+0

我有一個非常基礎的PHP知識,我很困惑它放在哪裏$ steamprofile ['avatar'] – shadowz

+0

它會返回一個圖片的URL。如果你想顯示圖像,請檢查我的編輯。 – MortenMoulder