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();
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 求学软件的前人们指明方向🥺
  • ¥50 如何增强飞上天的树莓派的热点信号强度,以使得笔记本可以在地面实现远程桌面连接
  • ¥15 MCNP里如何定义多个源?
  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services