成功登录我的网站后,如何正确进行会话

时间:2019-04-04 05:26:29

标签: php session

每次我尝试登录我的网站时,它都应该向我显示一条消息,表明您已登录,但没有发生。它会继续显示一条消息,指出我已注销,但我的任务栏向我显示了一条登录成功的消息。

我已经尝试了一切,但没有用:(

这是我的header.php

<?php
session_start();
?>
<?php
    if (isset($_SESSION['userId'])) {
        echo '<form action="Connectingdatabase/includes/logout.mrk.php" method="post">
                <button type="Submit" name="logout-submit">Log out</button>
            </form>';
        }
    else {
    echo '<form action="../includes/login.mrk.php" method="post">
            <input type="text" name="mailuid" placeholder="Username/E-mail">
            <input type="password" name="pwd" placeholder="Password">
            <button type="Submit" name="login-submit">Login</button>
          </form>';

这是我的index.php

<?php
 require "header.php";
?>
<?php
if (isset($_SESSION['userId'])) {
    echo '<p>You are logged in!</p>';
}
else {
    echo '<p>You are logged Out!</p>';
}
?>

这是我的login.php

if ($row = mysqli_fetch_assoc($result)) {
            $pwdCheck = password_verify($password, $row['pwdUsers']);
            if ($pwdCheck == false) {
            header("Location: ../systemlogintut/index1.php?error=wrongpwd");
            exit();     
            }
            else if ($pwdCheck == true) {
                session_start();
                $_SERVER['userId'] = $row['idUsers'];
                $_SERVER['userUid'] = $row['uidUsers'];
                header("Location: ../systemlogintut/index1.php?login=success");
            exit();
            }
            else {
            header("Location: ../systemlogintut/index1.php?error=wrongpwd");
            exit();
            }
        }
        else {
            header("Location: ../systemlogintut/index1.php?error=nouser");
            exit(); 

我的预期结果。如果我成功登录,它将不会显示登录表单,它应该会向我发送一条消息,提示我已登录,并且只给我导航栏上的“注销”按钮

0 个答案:

没有答案