验证后模态登录覆盖不会关闭?

时间:2015-10-02 16:39:02

标签: php html web bootstrap-modal

<?php require_once('authenticate.php');?>
<body>
<div id="login-modal" class="modal show"tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="display: none;">
  <div class="modal-dialog">
    <div class="loginmodal-container">
      <h1>Login to Your Account</h1>
      <br>
      <form method="post" action="login.php">
        <input type="text" name="username" id="username" placeholder="Username">
        <input type="password" name="password" id="password" placeholder="Password">
        <input type="submit" name="login" class="login loginmodal-submit" value="Login" onsubmit="window.location='index.php'"  >
      </form>
    </div>
  </div>
</div>
</body>

登录PHP:

<?php
  if ($_SERVER['REQUEST_METHOD'] == 'POST') {
      if(!empty($_POST["username"]) && !empty($_POST["password"])) {
          $username = $_POST["username"];
          $password = $_POST["password"];
          if($username == 'xxx' && $password =='xxxx') {    
              session_start();
              $_SESSION["authenticated"] = 'true';
              header("Location: index.php");
          }
          else {
              $_SESSION["authenticated"] = 'false';
              header("Location: index.php");
          }

      } else {
          $_SESSION["authenticated"] = 'false';
          header("Location: index.php");
      }
  }
?>

验证php:

<?php
session_start();
if(empty($_SESSION["authenticated"]) || $_SESSION["authenticated"] != 'true') {

  header('Location: login.php');
}else{
   echo '<script type="text/javascript">
        document.getElementById("login-modal").style.display = "none";  
        </script>';
}
?>

模式弹出窗口和用户名/密码已经过身份验证但叠加层没有关闭!此外,身份验证始终为真!但是,当我将登录设置在我的网站的单独页面中时,它确实有用,但我需要将它覆盖在我的网站上。感谢++

1 个答案:

答案 0 :(得分:0)

<?php
session_start();

if(empty($_SESSION["authenticated"]) || $_SESSION["authenticated"] != 'true') {
echo '<script type="text/javascript">
        document.getElementById("login-modal").style.display = "block";  
        </script>';
}
else{
    echo '<script type="text/javascript">
        document.getElementById("login-modal").style.display = "none";  
        </script>';
}
?>
相关问题