未定义的索引:steamid

时间:2017-09-09 07:02:23

标签: php steam

我一直在寻找解决方案但无法找到解决方案,因此最好的问题是StackOverFlow。

我不断收到错误未定义索引:steamid(第54行) 错误来自$ steamid = $ _SESSION [" steamid"];在欢迎页面上。

session_start();在标题中定义。 这是用户登录后重定向的欢迎页面。

------------------这是欢迎页面------------------

<?php include('../header.php'); ?>
    <?php include('../footer.php'); ?>

    <?php
    $steamid = $_SESSION["steamid"];

    require('../int/dbinit.php');

    $sql = "SELECT steamid FROM users WHERE steamid='". $steamid ."'";
    $result = $conn->query($sql);

    if ($result->num_rows > 0) {
        die("<!-- ACCOUNT ALREADY EXISTS! -->");
    }

    $sql = "INSERT INTO users (steamid) VALUES ('".$steamid."')";




    if ($conn->query($sql) === TRUE) {
      echo "<!-- ACCOUNT HAS BEEN CREATED! -->";
    } else {
      uhoh("Error while creating account: " . $sql . "<br>" . $conn->error);
    }

    ob_end_flush();

------------------这是一些登录页面------------------

  foreach ($json_decoded->response->players as $player)
                {
                    /*echo "
                    <br/>Player ID: $player->steamid
                    <br/>Player Name: $player->personaname
                    <br/>Profile URL: $player->profileurl
                    <br/>SmallAvatar: <img src='$player->avatar'/> 
                    <br/>MediumAvatar: <img src='$player->avatarmedium'/> 
                    <br/>LargeAvatar: <img src='$player->avatarfull'/> 
                    ";*/
                    $_SESSION["steamid"] = $player->steamid;
                    $_SESSION["personaname"] = $player->personaname;
                    $_SESSION["profileurl"] = $player->profileurl;
                    $_SESSION["avatar"] = $player->avatar;
                    $_SESSION["avatar_medium"] = $player->avatarmedium;
                    $_SESSION["avatar_full"] = $player->avatarfull;
                    /*var_dump($player);exit;*/

1 个答案:

答案 0 :(得分:-2)

使用isset()函数检查是否已定义。

$steamid = isset($_SESSION["steamid"]) ? $_SESSION["steamid"] : '';