如何添加Steam OpenID登录并记住用户登录cookie到我的网站?

Im trying to build a website where users will be able to login via Steam OpenID and do some stuff on the website.

But i would also like to implement some features that steam doesn't offer so:

If user come first time to the website and try to login he use steam OpenID feature to retrieve his user informations (the id is only passed on openID and the rest of informations i can take via API) but now i need to verify user first before i enable other site features, to verify user i need to check if he have more than 20 games on his account. If he have more than 20 games he is ok to continue to use website, if he don't have enough games post a notice that once he have enough game he can continue with login.

When the user is logedin and verified i need to insert his data into database to be able to connect him with features on my website, like counting comments, points,and other activity.

And finally once he is loged in remember him via cookie (there are sessions but as i know they are only valid until browser is closed) so cookie would be solution next time he come to website he don't need to login again.

I know how to do some stuff but in messy way i would be very grateful if someone could point me out and help me a bit how to achieve at least half of this.

So far the code i have is this one.

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);
}

}

douxiyi2418
douxiyi2418 toolong
大约 7 年之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐