我正在学习 PHP,并且我制作了一个简单的登录脚本,但问题是它只会将我重定向到一个空白页面。如果用户凭据正确,则意味着重定向到 index.php,但显然不是这样?还有验证,如果用户输入空白,则返回错误。这似乎没有被执行。
登录.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>
logininc.php // 我的处理页面
<?php
require_once("assets/configs/db_config.php");
$user=$_POST['user'];
$password=$_POST['password'];
if(isset($_POST['login']))
{
//To ensure that none of the fields are blank when submitting the form if
if($user || $password != NULL)
{
$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=mysql_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
{
print ('<div id="error">Computer says no.</div>');
}
print ('<div id="error">Enter something!</div>');
}
}
?>
index.php // 成功页面
<?php //module to check logins
session_start();
if(!isset($_SESSION["loggedIn"])){
header("Location: login.php");
exit;
}
Echo 'Congratulations <b>'.$_SESSION['user'].'</b> you successfully logged in!!<br />
Your Password is: <b>'.$_SESSION['password'].'</b><br />
<a href="login.php">Logout</a>';
?>