doumei1926 2017-01-30 14:30
浏览 97

MySQL脚本检索Steam ID,没有别的

I have a problem with the Steam Authentication for the web. As you know, Steam provides a script to allow people to connect on your site through the Steam database. My problem is my code only inserts the Steam ID in the database and not the name & avatar. My code:

if (isset($_GET['login'])){
require 'db.php';
require 'openid.php';
require 'userInfo.php';
try {
    require 'SteamConfig.php';

    $openid = new LightOpenID($steamauth['domainname']);

    if(!$openid->mode) {
        $openid->identity = 'http://steamcommunity.com/openid';
        header('Location: ' . $openid->authUrl());
    } elseif ($openid->mode == 'cancel') {
        echo 'User has canceled authentication!';
    } else {
        if($openid->validate()) { 
            $id = $openid->identity;
            $ptn = "/^http:\/\/steamcommunity\.com\/openid\/id\/(7[0-9]{15,25}+)$/";
            preg_match($ptn, $id, $matches);

            $_SESSION['steamid'] = $matches[1];

                $sql_fetch_id = "SELECT * FROM member WHERE steamid = '".$_SESSION['steamid']."'";
                $query_id = mysqli_query($db, $sql_fetch_id);

                if (mysqli_num_rows($query_id) == 0) {
                    $sql_steam = "INSERT INTO member (name, steamid, avatar) VALUES  ('".$_SESSION['personaname']."', '".$_SESSION['steamid']."', '".$_SESSION['avatar']."')";
                    mysqli_query($db, $sql_steam);
                }

            if (!headers_sent()) {
                header('Location: '.$steamauth['loginpage']);
                exit;
            } else {
                ?>
                <script type="text/javascript">
                    window.location.href="<?=$steamauth['loginpage']?>";
                </script>
                <noscript>
                    <meta http-   equiv="refresh" content="0;url=<?=$steamauth['loginpage']?>" />
                </noscript>
                <?php
                exit;
            }

            } else {
            echo "User is not logged in.
";
        }
    }
} catch(ErrorException $e) {
    echo $e->getMessage();
}
 }

Screenshot screenshot

  • 写回答

1条回答 默认 最新

  • duankekan9269 2017-01-30 15:50
    关注

    Looking at the output of var_dump($_SESSION) (which should be in the question) it seems as if you're not actually referencing the keys of the session correctly.

    With this line of code:

    $sql_steam = "INSERT INTO member (name, steamid, avatar) VALUES  ('".$_SESSION['personaname']."', '".$_SESSION['steamid']."', '".$_SESSION['avatar']."')";
    

    You're referencing $_SESSION['personaname'], however, only ['steam_personaname'] is provided in the session. So you're referencing something that isn't there.

    So you should be using:

    $sql_steam = "INSERT INTO member (name, steamid, avatar) VALUES  ('".$_SESSION['steam_personaname']."', '".$_SESSION['steamid']."', '".$_SESSION['steam_avatarfull']."')";
    
    评论

报告相同问题?

悬赏问题

  • ¥15 matlab有限元法求解梁带有若干弹簧质量系统的固有频率
  • ¥15 找一个网络防御专家,外包的
  • ¥100 能不能让两张不同的图片md5值一样,(有尝)
  • ¥15 informer代码训练自己的数据集,改参数怎么改
  • ¥15 请看一下,学校实验要求,我需要具体代码
  • ¥50 pc微信3.6.0.18不能登陆 有偿解决问题
  • ¥20 MATLAB绘制两隐函数曲面的交线
  • ¥15 求TYPCE母转母转接头24PIN线路板图
  • ¥100 国外网络搭建,有偿交流
  • ¥15 高价求中通快递查询接口