【发布时间】:2023-03-05 07:14:01
【问题描述】:
这里是我开始会话的地方。
login.php
<?php
require_once("db.php");
require_once("functions.php");
if(isset($_POST['submit'])) {
global $connection;
$username = $_POST['username'];
$safe_username = mysqli_real_escape_string($connection, $username);
$password = $_POST['password'];
$query = "SELECT * FROM admin WHERE username = '{$safe_username}'";
$result = mysqli_query($connection, $query);
if($row = mysqli_fetch_assoc($result)) {
$set_password = $row['password'];
$input_password = crypt($password, $set_password);
if($input_password == $set_password) {
session_start();
$_SESSION['username'] = $safe_username;
header("location:users-area.php");
} else {
die(header("location:index.php?loginFailure=true"));
}
} else {
die(header("location:index.php?loginFailure=true"));
}
}
?>
listall.php
这是我检查它的地方。
<?php
session_start();
if(emtpy ($_SESSION['username'])){
header("location:../login/index.php");
}
由于某种原因这不起作用,如果您未登录,它会带您返回登录页面,如果您正确登录,则允许您通过 listall.php。
希望有人能找到问题。
【问题讨论】:
-
listall.php 应该是
if(empty($_SESSION['username'])) -
session_start() 必须首先调用,无论逻辑如何。把它贴在页面顶部,在
-
你写的是 ETMPY 而不是 EMPTY