Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/273.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何向我的站点添加Steam OpenID登录并记住用户使用cookie登录?_Php_Cookies_Openid_Registration_Steam - Fatal编程技术网

Php 如何向我的站点添加Steam OpenID登录并记住用户使用cookie登录?

Php 如何向我的站点添加Steam OpenID登录并记住用户使用cookie登录?,php,cookies,openid,registration,steam,Php,Cookies,Openid,Registration,Steam,我正在尝试建立一个网站,用户可以通过Steam OpenID登录并在网站上做一些事情 但我还想实现一些steam不提供的功能: 如果用户第一次访问网站并尝试登录,他将使用steam OpenID功能检索其用户信息(id仅通过OpenID传递,其余信息我可以通过API获取),但现在我需要先验证用户,然后再启用其他网站功能,为了验证用户,我需要检查他的帐户上是否有超过20个游戏。若他有超过20个游戏,他可以继续使用网站,若他并没有足够的游戏,发布一个通知,一旦他有足够的游戏,他可以继续登录 当用户登

我正在尝试建立一个网站,用户可以通过Steam OpenID登录并在网站上做一些事情

但我还想实现一些steam不提供的功能:

如果用户第一次访问网站并尝试登录,他将使用steam OpenID功能检索其用户信息(id仅通过OpenID传递,其余信息我可以通过API获取),但现在我需要先验证用户,然后再启用其他网站功能,为了验证用户,我需要检查他的帐户上是否有超过20个游戏。若他有超过20个游戏,他可以继续使用网站,若他并没有足够的游戏,发布一个通知,一旦他有足够的游戏,他可以继续登录

当用户登录并验证后,我需要将他的数据插入数据库,以便能够将他与我网站上的功能连接起来,如计算评论、分数和其他活动

最后,当他登录后,通过cookie记住他(有一些会话,但我知道它们只有在浏览器关闭时才有效),所以cookie将是下次他访问网站时的解决方案,他不需要再次登录

我知道如何做一些事情,但在混乱的方式,我会非常感谢,如果有人能指出我,并帮助我一点如何实现至少一半这一点

到目前为止,我的代码是这个

function login() {
$openid = new LightOpenID(SITEURL);

if(!$openid->mode) {

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

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

elseif($openid->mode == 'cancel') {
    echo 'User has canceled Authentication.';
}

elseif(!isset($_SESSION['RaffleSteamAuth'])) {

        $_SESSION['RaffleSteamAuth'] = $openid->validate() ? $openid->identity : null;
        $_SESSION['RaffleSteamID64'] = str_replace('http://steamcommunity.com/openid/id/', '',$_SESSION['RaffleSteamAuth']);
        if($_SESSION['RaffleSteamAuth'] != null) {
            $steam64 = str_replace('http://steamcommunity.com/openid/id/', '', $_SESSION['RaffleSteamAuth']);
            $profile = file_get_contents('http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=' . APIKEY . '&steamids=' . $steam64);
            $buffer = fopen('cache/' . $steam64 . '.json', 'w+');
            fwrite($buffer, $profile);
            fclose($buffer);
        }

        header('Location: ' . SITEURL);
    }

if(isset($_SESSION['RaffleSteamAuth'])) {
    $steam = json_decode(file_get_contents('cache/' . $_SESSION['RaffleSteamID64'] . '.json'));
    echo '<li class="dropdown">';
    echo '<a href="#" class="dropdown-toggle" data-toggle="dropdown"><img src="' . $steam->response->players[0]->avatar . '"/> ' . $steam->response->players[0]->personaname .'<b class="caret"></b></a>';
    echo '<ul class="dropdown-menu">';
    echo '<li><a href="?go=logout">Logout</a></li>';
    echo '</ul>';
    echo '</li>';

}

if(isset($_GET['go']) && $_GET['go'] == 'logout' ){
    unset($_SESSION['RaffleSteamAuth']);
    unset($_SESSION['RaffleSteamID64']);
    header('Location: ' . SITEURL);
}
函数登录(){
$openid=新的LightOpenID(SITEURL);
如果(!$openid->模式){
如果(isset($\u GET['go'])&&&$\u GET['go']=='login'){
$openid->identity=http://steamcommunity.com/openid';
标题('Location:'。$openid->authUrl());
}
如果(!isset($\u会话['RaffleSteamAuth'])){
回音“
  • ”; } } elseif($openid->mode=='cancel'){ echo“用户已取消身份验证”; } elseif(!isset($\u会话['RaffleSteamAuth'])){ $\u会话['RaffleSteamAuth']=$openid->validate()?$openid->identity:null; $\会话['RaffleSteamID64']=str\u替换('http://steamcommunity.com/openid/id/“,”,$_会话['RaffleSteamAuth]); if($\会话['RaffleSteamAuth']!=null){ $steam64=str_替换('http://steamcommunity.com/openid/id/“,”,$_会话['RaffleSteamAuth]); $profile=文件\u获取\u内容('http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=“.APIKEY.&streamids=”。$stream64); $buffer=fopen('cache/'.$stream64'.json','w+'); fwrite($buffer,$profile); fclose(缓冲区); } 标题(“位置:”.SITEURL); } if(isset($\u会话['RaffleSteamAuth'])){ $steam=json_decode(文件_获取_内容('cache/'.$会话['RaffleSteamID64']..json'); echo'
  • ; 回声'; echo'
      ; 回音“
    • ”; 回声“
    ”; 回音“
  • ”; } 如果(设置($\u GET['go'])&&&$\u GET['go']=='logout')){ 取消设置($_会话['RaffleSteamAuth']); 取消设置($_会话['RaffleSteamID64']); 标题(“位置:”.SITEURL); }
    }

    您可能重复了同一个问题。我回答了。