【问题标题】:when i use this code in localhost it work, but when i use in my website it not working当我在本地主机中使用此代码时它可以工作,但是当我在我的网站中使用它时它不起作用
【发布时间】:2014-05-03 07:03:41
【问题描述】:

我在 localhost 中使用此代码

     include "apikey.php"; // My api key
    include "OpenId.php"; //Official light open id lib.
        $OpenID = new LightOpenID("http://4pstore.com/");
$api = B5F1409CA6FFE70A2CFB98C870A6A9F5;
    session_start();

    if(!$OpenID->mode){

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

        if(!isset($_SESSION['T2SteamAuth'])){
            echo "<a href=\"?login\"><img src=\"http://cdn.steamcommunity.com/public/images/signinthroughsteam/sits_small.png\" border=\"0\"/></a>";
    }

    } elseif($OpenID->mode == "cancel"){
        echo "User has canceled Authenticiation.";
    } 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+");
                file_put_contents("cache/{$Steam64}.json", $profile);
                fclose($buffer);

            }

            header("Location: index.php");

        }

    }



    if(isset($_SESSION['T2SteamAuth'])){        
        echo "<div id=\"login\"><a href=\"?logout\">Logout</a></div>";
    $steam = json_decode(file_get_contents("cache/{$_SESSION['T2SteamID64']}.json"));
        echo "<img src=\"{$steam->response->players[0]->avatarfull}\"/>";


    }

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

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

    } 

它有结果,可以访问steam信息,图片一切,它像这样写入文件名76561198023220354.json

{
"response": {
    "players": [
        {
            "steamid": "76561198023220354",
            "communityvisibilitystate": 3,
            "profilestate": 1,
            "personaname": "KLoGic",
            "lastlogoff": 1399082572,
            "profileurl": "http://steamcommunity.com/id/klogic/",
            "avatar": "http://media.steampowered.com/steamcommunity/public/images/avatars/ee/eef75511ba1f16b66e9ac45346e7c0f790a6551a.jpg",
            "avatarmedium": "http://media.steampowered.com/steamcommunity/public/images/avatars/ee/eef75511ba1f16b66e9ac45346e7c0f790a6551a_medium.jpg",
            "avatarfull": "http://media.steampowered.com/steamcommunity/public/images/avatars/ee/eef75511ba1f16b66e9ac45346e7c0f790a6551a_full.jpg",
            "personastate": 1,
            "realname": "KLoGic",
            "primaryclanid": "103582791433445765",
            "timecreated": 1269915414,
            "personastateflags": 0,
            "loccountrycode": "TH"
        }
    ]

}

}

但是当我在我的网站上使用此代码时,它无法访问 Steam 信息、图片和文件 76561198023220354.json 上它只说

<html> <head> <title>404 Not Found</title> </head> <body> <h1>Not Found</h1> </body> </html>

请帮帮我:(

【问题讨论】:

    标签: php steam steam-web-api


    【解决方案1】:

    我自己也有这个问题。我发现我的服务器不允许使用file_get_contents(),只是从传递给它的 URL 返回了 404 错误。您可以使用自定义file_get_contents_curl() 命令解决此问题。这是我用的那个:

    function file_get_contents_curl($url) {
        $ch = curl_init();
    
        curl_setopt($ch, CURLOPT_HEADER, false);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 15);
    
        $data = curl_exec($ch);
        curl_close($ch);
    
        return $data;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-10-08
      • 1970-01-01
      • 1970-01-01
      • 2021-08-02
      • 2020-07-04
      • 1970-01-01
      • 2022-09-30
      • 1970-01-01
      相关资源
      最近更新 更多