Steam OpenID PHP and HTML


Steam OpenID PHP and HTML

所以我试图为我的网站做一个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

我为我的steam网站使用相同的代码看到这里。

            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链接和使用框架连接它们与一个和另一个。

如你所说

{
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');

echo $ sign_inout;

感谢您花时间阅读这篇文章!