我试图根据此序列中的会话编写一个简单的登录系统。 虽然在第一个位置登录用户工作但第二个用户没有登录。我无法找到错误的位置。 以下是 login.php 表单的代码。
include './user.php';
session_start();
if (!empty($_POST['form-username'])) {
if($_POST['form-username']==$user && $_POST['form-password']==$pass){
$_SESSION['login'] = $_POST['form-username'];
$_SESSION['password'] = $_POST['form-password'];
header("Location: ./dashboard.php");
}else if($_POST['form-username']==$user2 && $_POST['form-password']==$pass2){
$_SESSION['login'] = $_POST['form-username'];
$_SESSION['password'] = $_POST['form-password'];
header("Location: ./dashboard.php");
}
else {
header("Location: ./index.php?err");
//exit;
}
}
if(!empty($_SESSION['login'])):
if($_SESSION['login']==$user AND $_SESSION['password']==$pass || $_SESSION['login']==$user2 AND $_SESSION['password']==$pass2){
header("Location: ./dashboard.php");
}
endif;
以下是 user.php 文件的代码:
<?php
$user = 'panel1';
$pass = 'panel123';
$user2 ='panel2';
$pass2 = 'panel091';
答案 0 :(得分:2)
我认为您应该尝试将上一个if
声明更改为:
if (($_SESSION['login'] == $user AND $_SESSION['password'] == $pass) OR ($_SESSION['login'] == $user2 AND $_SESSION['password'] == $pass2)) {
// ...
}
注意每个条件周围的包裹约束。