无法在其他页面上访问PHP Session变量

时间:2018-09-22 12:24:23

标签: php

所以我正在使用会话变量来创建SweetAlerts弹出窗口。现在,这些相同的方法可以在其他页面上使用,但是我不知道。

在我的第一页上,有:

$sql = mysqli_query($conn, "SELECT * FROM users WHERE user_id='".$user_ID."'");
if($row = mysqli_fetch_array($sql))
{
    $FirstName = $row['user_first'];
    $LastName = $row['user_last'];
    $Email = $row['user_email'];
    $Username = $row['user_uid'];
    $_SESSION['user_Username'] = $row['user_uid'];
    $Gamertag = $row['user_gamertag'];
    $Platform = $row['user_platform'];
    $Verified = $row['verified'];
    $admin = $row['admin'];
    $_SESSION['adminlvl'] = $row['admin'];
    $suspend = $row['suspend'];
    $ban = $row['ban'];
    $country = $row['country'];
    $adminlvl = $row['admin'];
} else {
    $_SESSION['eMessage'] = "That user does not exist!";
    $_SESSION["eMessageType"] = "error";
    $_SESSION["eMessageTitle"] = "Four Oh Four!";
    header("Location: index.php");
}

index.php(重定向到的页面):

<script>
    function PopupMessage(){
        swal("<?php echo $_SESSION['eMessageTitle'];?>", "<?php echo $_SESSION['eMessage'];?>", "<?php echo $_SESSION['eMessageType'];?>");
    }
</script>

<?php if (isset($_SESSION['eMessage'])){?>
    <script>PopupMessage();</script>
    <?php
        unset($_SESSION['eMessage']);
        unset($_SESSION['eMessageTitle']);
        unset($_SESSION['eMessageType']);
        }

问题是,当它重定向到弹出窗口的index.php时,不会弹出。现在,我在另一个页面上具有相同的EXACT方法,该方法重定向到index.php页面,并且弹出窗口起作用。因此,如果我删除“页眉”,则页面将加载并且弹出窗口将弹出。我不知道为什么会这样。

0 个答案:

没有答案