我一直在尝试向我的网站添加用户登录系统,并且以下登录页面似乎工作正常(就它检查用户名和密码而言,通过用户通过):
索引.php
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Login Form</title>
</head>
<body>
<form id="form1" name="form1" method="post" action="login.php">
<table width="510" border="0" align="center">
<tr>
<td colspan="2">Login Form</td>
</tr>
<tr>
<td>Email Address:</td>
<td><input type="text" name="email" id="email" /></td>
</tr>
<tr>
<td>Password</td>
<td><input type="password" name="password" id="password" /></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="button" id="button" value="Submit" /></td>
</tr>
<tr>
<td colspa"2"><?php if(isset($_GET['f'])){echo("<h2>Login Failed</h2>");} ?></td>
</tr>
</table>
</form>
</body>
</html>
登录.php
<?php
session_start();
$email = $_POST['email'];
$password = $_POST['password'];
include 'includes/db_connect.php';
$conn = new PDO($dsn, $user, $pass);
$query = "SELECT password, salt FROM member WHERE email = :email";
$result = $conn->prepare($query);
$result->bindParam(":email", $email);
$result->execute();
$number_of_rows = $result->rowCount();
但是,我总是收到“您不是授权用户...”错误,我试过将 avar_dump()和var_export()for$_SESSION但得到NULL并print_r没有产生任何结果,echo 也是如此$_SESSION['email'],这表明我的$_SESSION全局为空,我session_start();在login.php 和 results.php 都开始,所以会话应该在那里并继续。
我在同一台服务器上安装了诸如 WordPress 之类的东西,所以很确定诸如$_SESSION在主机上运行之类的东西,而且 PHP 是 7.2,所以也应该符合要求。
我忽略了什么愚蠢的错误?
尚方宝剑之说