0

这是一种 Steam 身份验证方法,但它给了我一些通知,所以有人可以帮我解决这个问题

    <?php 

$steam_login_verify = SteamSignIn::validate();
if(!empty($steam_login_verify))
{
echo "success + $steam_login_verify";
}
else
{
$steam_sign_in_url = SteamSignIn::genUrl();
echo '<a href=\"$steam_sign_in_url\"><img src="http://cdn.steamcommunity.com/public/images/signinthroughsteam/sits_large_noborder.png"/></a>';
}
/**
*
* @package Steam Community API
* @copyright (c) 2010 ichimonai.com
* @license http://opensource.org/licenses/mit-license.php The MIT License
*
*/

class SteamSignIn
{
    const STEAM_LOGIN = 'https://steamcommunity.com/openid/login';

    /**
    * Get the URL to sign into steam
    *
    * @param mixed returnTo URI to tell steam where to return, MUST BE THE FULL URI WITH THE PROTOCOL
    * @param bool useAmp Use &amp; in the URL, true; or just &, false. 
    * @return string The string to go in the URL
    */
    public static function genUrl($returnTo = false, $useAmp = true)
    {
        $returnTo = (!$returnTo) ? (!empty($_SERVER['HTTPS']) ? 'https' : 'http') . '://' . $_SERVER['HTTP_HOST'] . $_SERVER['SCRIPT_NAME'] : $returnTo;

        $params = array(
            'openid.ns'         => 'http://specs.openid.net/auth/2.0',
            'openid.mode'       => 'checkid_setup',
            'openid.return_to'  => $returnTo,
            'openid.realm'      => (!empty($_SERVER['HTTPS']) ? 'https' : 'http') . '://' . $_SERVER['HTTP_HOST'],
            'openid.identity'   => 'http://specs.openid.net/auth/2.0/identifier_select',
            'openid.claimed_id' => 'http://specs.openid.net/auth/2.0/identifier_select',
        );

        $sep = ($useAmp) ? '&amp;' : '&';
        return self::STEAM_LOGIN . '?' . http_build_query($params, '', $sep);
    }

    /**
    * Validate the incoming data
    *
    * @return string Returns the SteamID64 if successful or empty string on failure
    */
    public static function validate()
    {
        // Star off with some basic params
        $params = array(
            'openid.assoc_handle'   => $_GET['openid_assoc_handle'],
            'openid.signed'         => $_GET['openid_signed'],
            'openid.sig'            => $_GET['openid_sig'],
            'openid.ns'             => 'http://specs.openid.net/auth/2.0',
        );

        // Get all the params that were sent back and resend them for validation
        $signed = explode(',', $_GET['openid_signed']);
        foreach($signed as $item)
        {
            $val = $_GET['openid_' . str_replace('.', '_', $item)];
            $params['openid.' . $item] = get_magic_quotes_gpc() ? stripslashes($val) : $val; 
        }

        // Finally, add the all important mode. 
        $params['openid.mode'] = 'check_authentication';

        // Stored to send a Content-Length header
        $data =  http_build_query($params);
        $context = stream_context_create(array(
            'http' => array(
                'method'  => 'POST',
                'header'  => 
                    "Accept-language: en\r\n".
                    "Content-type: application/x-www-form-urlencoded\r\n" .
                    "Content-Length: " . strlen($data) . "\r\n",
                'content' => $data,
            ),
        ));

        $result = file_get_contents(self::STEAM_LOGIN, false, $context);

        // Validate wheather it's true and if we have a good ID
        preg_match("#^http://steamcommunity.com/openid/id/([0-9]{17,25})#", $_GET['openid_claimed_id'], $matches);
        $steamID64 = is_numeric($matches[1]) ? $matches[1] : 0;

        // Return our final value
        return preg_match("#is_valid\s*:\s*true#i", $result) == 1 ? $steamID64 : '';
    }
}        

?>

这是通过 Steam 方法进行的简单登录,我从这里http://forums.steampowered.com/forums/showthread.php?t=1430511发现了 哪些错误?有错误

注意:未定义的索引:第 130 行 C:\Users\karan\Desktop\xampp\htdocs\LOL\index.php 中的 openid_assoc_handle

注意:未定义的索引:openid_signed in C:\Users\karan\Desktop\xampp\htdocs\LOL\index.php 在第 131 行

注意:未定义的索引:第 132 行 C:\Users\karan\Desktop\xampp\htdocs\LOL\index.php 中的 openid_sig

注意:未定义的索引:openid_signed in C:\Users\karan\Desktop\xampp\htdocs\LOL\index.php 在第 137 行

注意:未定义的索引:C:\Users\karan\Desktop\xampp\htdocs\LOL\index.php 中的 openid_ 第 140 行

注意:未定义的索引:第 163 行 C:\Users\karan\Desktop\xampp\htdocs\LOL\index.php 中的 openid_claimed_id

注意:未定义的偏移量:第 164 行 C:\Users\karan\Desktop\xampp\htdocs\LOL\index.php 中的 1

好吧,我不知道为什么会出现这些错误 http://i.imgur.com/pedSj7k.png 在此先感谢_Frost

4

1 回答 1

0

根据您链接的线程中的评论,该方法似乎不再有效。我在此答案中提供了另一种使用 Steam API 身份验证的方法,可能对您有所帮助。

于 2013-10-22T02:35:20.023 回答