vendredi 2 octobre 2015

modal login overlay does not close after authentication?

<?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>

Login 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");
      }
  }
?>

Authenticate 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>';
}
?>

The modal popup and the username/password authenticated but the overlay do not close!Also the authentication is always true! However, it worked out when I put login in separate page from my website but I need it to be overlay on my website. thanks++




Aucun commentaire:

Enregistrer un commentaire