douwang9650 2015-11-15 15:36
浏览 339

Steam登录Lightopenid

I have created a index.php for my login with steam for user to use there steam login for my site to get information like their name, avatar, and steam id the problem i'm having is that the data isn't sending to my database I have made a db.php file with all the right details just it's not storing in my database.

$db = mysql_connect("localhost", "username", "password");
$db = mysql_select_db("mydbname");



echo "
                <br/>SmallAvatar: <img src='$player->avatar'/>
                <br/>Player ID: $player->steamid
                <br/>Player Name: $player->personaname
                <br/>Profile URL: $player->profileurl 
                ";
            $sql_fetch_id = "SELECT * FROM users_steam WHERE steamid = '$player->steamid'";
            $query_id = mysqli_query($db, $sql_fetch_id);

            $_SESSION['name'] = $player->personaname;
            $_SESSION['steamid'] = $player->steamid;
            $_SESSION['avatar'] = $player->avatar;

            if (mysqli_num_rows($query_id) == 0) {
                $sql_steam = "INSERT INTO users_steam (name, steamid, avatar) VALUES  ('$player->personaname', '$player->steamid', '$player->avatar')";
                mysqli_query($db, $sql_steam);
            }
  • 写回答

1条回答 默认 最新

  • dousu5608 2015-11-15 15:56
    关注

    Try this:

    require 'openid.php';
    
    include_once("db.php");
    
    $_STEAMAPI = "";
    
    try {
        $openid = new LightOpenID('www.audiochat.xyz/index.php');
        if(!$openid->mode) {
            if(isset($_GET['login'])) {
                $openid->identity = 'http://steamcommunity.com/openid/?l=english';
                header('Location: ' . $openid->authUrl());
            } else {
                echo "<h2>Connect to Steam</h2>";
                echo "<form action='?login' method='post'>";
                echo "<input type='image' src='http://cdn.steamcommunity.com/public/images/signinthroughsteam/sits_small.png'>";
                echo "</form>";
            }
        } 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);
    
                $url = "http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=$_STEAMAPI&steamids=$matches[1]";
                $json_object= file_get_contents($url);
                $json_decoded = json_decodemysql_select_db($json_object);
    
            foreach ($json_decoded->response->players as $player)
            {
                    $sql_fetch_id = "SELECT * FROM users_steam WHERE steamid = $player->steamid";
                    $query_id = mysqli_query($db, $sql_fetch_id);
    
                    if (mysqli_num_rows($query_id) == 0) {
                        $sql_steam = "INSERT INTO users_steam (name, steamid, avatar) VALUES  ('$player->personaname', '$player->steamid', '$player->avatar')";
                        mysqli_query($db, $sql_steam);
                    }
                }
            } else {
                            echo "User is not logged in.
    ";
            }
        }
    } catch(ErrorException $e) {
        echo $e->getMessage();
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥20 iqoo11 如何下载安装工程模式
  • ¥15 本题的答案是不是有问题
  • ¥15 关于#r语言#的问题:(svydesign)为什么在一个大的数据集中抽取了一个小数据集
  • ¥15 C++使用Gunplot
  • ¥15 这个电路是如何实现路灯控制器的,原理是什么,怎么求解灯亮起后熄灭的时间如图?
  • ¥15 matlab数字图像处理频率域滤波
  • ¥15 在abaqus做了二维正交切削模型,给刀具添加了超声振动条件后输出切削力为什么比普通切削增大这么多
  • ¥15 ELGamal和paillier计算效率谁快?
  • ¥15 蓝桥杯单片机第十三届第一场,整点继电器吸合,5s后断开出现了问题
  • ¥15 file converter 转换格式失败 报错 Error marking filters as finished,如何解决?