dongnao9525 2014-05-03 07:03
浏览 64

当我在localhost中使用此代码时,它可以工作,但是当我在我的网站中使用它时,它无法正常工作

i use this code in 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");

    } 

it have result , can access steam information , picture everything and it write to file name 76561198023220354.json like this

{
"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"
        }
    ]

}

}

but when i use this code it my website , it can't access steam information , picture everything and on file 76561198023220354.json it only say

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

help me please :(

  • 写回答

1条回答 默认 最新

  • douban2014 2014-06-06 20:46
    关注

    I also had this problem myself. I found out that my server wouldn't allow the use of file_get_contents() and just returned a 404 error from the URL passed to it. You can solve this problem with a custom file_get_contents_curl() command. Here's the one I used:

    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;
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在node.js中或者java中给wav格式的音频编码成sil格式呢
  • ¥15 不小心不正规的开发公司导致不给我们y码,
  • ¥15 我的代码无法在vc++中运行呀,错误很多
  • ¥50 求一个win系统下运行的可自动抓取arm64架构deb安装包和其依赖包的软件。
  • ¥60 fail to initialize keyboard hotkeys through kernel.0000000000
  • ¥30 ppOCRLabel导出识别结果失败
  • ¥15 Centos7 / PETGEM
  • ¥15 csmar数据进行spss描述性统计分析
  • ¥15 各位请问平行检验趋势图这样要怎么调整?说标准差差异太大了
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题