我有一个这个登录脚本:
<?php
session_start();
$username = $_POST['username'];
$password = $_POST['password'];
include 'includes/connect.php';
$username = mysqli_real_escape_string($con, $username);
$query = "SELECT password, salt
FROM member
WHERE username = '$username';";
$result = mysqli_query($con, $query);
if(mysqli_num_rows($result) == 0)
{
header('Location: login.html');
}
$userData = mysqli_fetch_array($result, MYSQL_ASSOC);
$hash = hash('sha256', $userData['salt'] . hash('sha256', $password) );
$_SESSION['username']=$username;
if($hash != $userData['password'])
{
header('Location: login.html');
}else{ // Redirect to home page after successful login.
$_SESSION['username']=$username;
header('Location: stats.php');
}
?>
那么这是stats.php:
<?php
session_start();
if(!isset($_SESSION['username'])){
header("Location:register.html");
}
?>
下面是我的 html 5 文档。
但是我是否登录都没有关系,它仍然允许我访问 stats.php