1 回答
TA贡献1797条经验 获得超6个赞
session_start 需要位于代码的第一行...我看到您在另一页上有这个,但是,这个仍然是错误的;)否则,在 isset 之前执行: print_r($_SESSION);
<?php
session_start();
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "phpmysql";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$user1 = $email1 = $pass1 = "";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$user1 = test_input($_POST["usrname"]);
$pass1 = test_input($_POST["psw"]);
}
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
$sql = "SELECT username, password, email FROM users";
$result = $conn->query($sql);
$row = $result->fetch_array();
if ($row["username"]==$user1 && $row["password"]==$pass1) {
$_SESSION["username"] = $row["username"];
//$_SESSION["email"] = $row["email"];
header("Location: Main_login_authentication.php");
} else {
header("Location: Denied.php");
}
$conn->close();
?>
- 1 回答
- 0 关注
- 84 浏览
添加回答
举报