【问题标题】:Steam OpenID PHP and HTMLSteam OpenID PHP 和 HTML
【发布时间】:2015-10-06 20:10:38
【问题描述】:

所以我也在尝试为我的网站制作一个 Steam 登录按钮,但它并没有重定向到我想要的位置。相反,它只是将用户引导到带有用户名和注销按钮的普通站点。我没有写这个代码,我只是复制别人只是为了尝试它。我正在尝试将其引导回 index.php,但它也不想要。 代码如下:

<?php
                        error_reporting(E_ERROR | E_PARSE | E_WARNING);

$user = new user;
$user->apikey = ""; // put your API key here
$user->domain = "localhost/index.php"; // put your domain


class user
{
    public static $apikey;
    public static $domain;

    public function GetPlayerSummaries ($steamid)
    {
        $response = file_get_contents('http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=' . $this->apikey . '&steamids=' . $steamid);
        $json = json_decode($response);
        return $json->response->players[0];
    }

    public function signIn ()
    {
        require_once 'openid.php';
        $openid = new LightOpenID($this->domain);// put your domain
        if(!$openid->mode)
        {
            $openid->identity = 'http://steamcommunity.com/openid';
            header('Location: ' . $openid->authUrl());
        }
        elseif($openid->mode == 'cancel')
        {
            print ('User has canceled authentication!');
        }
        else
        {
            if($openid->validate())
            {
                preg_match("/^http:\/\/steamcommunity\.com\/openid\/id\/(7[0-9]{15,25}+)$/", $openid->identity, $matches); // steamID: $matches[1]
                setcookie('steamID', $matches[1], time()+(60*60*24*7), '/'); // 1 week
                header('Location: /');
                exit;
            }
            else
            {
                print ('fail');
            }
        }
    }
}

if(isset($_GET['login']))
{
    $user->signIn();
}
if (array_key_exists( 'logout', $_POST ))
{
    setcookie('steamID', '', -1, '/');
    header('Location: /');
}


if(!$_COOKIE['steamID'])
{
    print ('<form action="?login" method="post">
        <input type="image" src="http://cdn.steamcommunity.com/public/images/signinthroughsteam/sits_large_border.png"/>
        </form>');
}
else
{
    print('<form method="post"><button title="Logout" name="logout">Logout</button></form>');
    echo $user->GetPlayerSummaries($_COOKIE['steamID'])->personaname;
}




?>

我删除了 Apikey,因为我不知道它是否保存只是为了把它放到网上让大家看到这样。 谢谢大家:) 有一个很棒的一天。对不起我的语法,我的英语不是那么好。再次感谢:D

【问题讨论】:

    标签: php openid steam-web-api


    【解决方案1】:

    我在我的 Steam 网站上使用相同的代码 See here.

                preg_match("/^http:\/\/steamcommunity\.com\/openid\/id\/(7[0-9]{15,25}+)$/", $openid->identity, $matches); // steamID: $matches[1]
                setcookie('steamID', $matches[1], time()+(60*60*24*7), '/'); // 1 week
                header('Location: /');
                exit;
    

    在那个代码区域,应该有一个修复。 我似乎找不到我的 php,因为我用 2 个 php 链接使我的 php 变得非常复杂,并使用框架将它们相互连接起来。

    如你所说

    {
    print('<form method="post"><button title="Logout" name="logout">Logout</button></form>');
    echo $user->GetPlayerSummaries($_COOKIE['steamID'])->personaname; 
    }
    

    我是这样制作的,登录/注销按钮加载了这个 php 代码。不确定这是否会对您有所帮助! 如果您使用此代码,请确保您为登出网站启用了allow_url_fopen

    $sign_inout = file_get_contents('http://kuramacraft.net/steam/signinout.php');

    回显 $sign_inout;

    感谢您抽出宝贵时间阅读本文!

    【讨论】:

      猜你喜欢
      • 2014-03-29
      • 2015-05-12
      • 2013-12-27
      • 2019-05-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-10-28
      相关资源
      最近更新 更多