我的登录页面似乎使用任何登录字段输入将我重定向到 index.php。这是出乎意料的,因为它应该执行检查。此外,如果登录字段留空,它会重定向到空白页面。这也不应该是这样,因为我已经设置了一个条件来处理这个结果。看
登录文件
<?php
require_once("assets/configs/db_config.php");
$user=$_POST['user'];
$password=$_POST['password'];
if(isset($_POST['submit'])){
//To ensure that none of the fields are blank when submitting the form if
if($user != NULL || $password != NULL)
// if(isset($_POST['user']) && isset($_POST['password'])) old code
{
$user = stripslashes($user);
$password = stripslashes($password);
$user = mysqli_real_escape_string($user);
$password = mysqli_real_escape_string($password);
$sql="SELECT * FROM $test_db WHERE user='$user' and password='$password'";
$result=mysqli_query($sql);
$row=mysqli_fetch_array($result);
if($row['user'] == $user && $row['password'] == $password)
{
session_start();
$_SESSION['user'] = $user;
$_SESSION['password'] = $password;
$_SESSION['loggedin'] = "true";
header("location:index.php");
}
else
{
echo ('<div id="error">Computer says no.</div>');
}
echo ('<div id="error">Enter something!</div>');
}
}
登录.php
<form id="login-form" method="post" action="logininc.php"> <fieldset>
<legend>Login </legend>
<p>Please enter your username and password to access the administrator's panel</p>
<label for="user"> <input type="text" name="user" placeholder="Type your username here" id="user" /></label>
<label for="password"> <input type="password" name="password" placeholder="Type your password here" id="password" /></label>
<label for="submit"> <input type="submit" class="btn btn-primary"name="submit" id="submit" value="Login" /> </label> </fieldset> </form>
请指教。