php - PHP登录系统验证问题
问题描述
我正在研究简单的登录系统。我的代码以前运行良好,但现在我添加了在用户登录时显示 php 页面的功能。我正在使用 MySQL 来存储登录信用。代码分为三个部分。登录表单,连接到 MySQL 和身份验证。我还添加test.html
了测试系统(错误的密码 -> 重定向到test.html
)。
我的代码 auth.php
<?php
include('connect.php');
$username = $_POST['user'];
$password = $_POST['pass'];
//to prevent from mysqli injection
$username = stripcslashes($username);
$password = stripcslashes($password);
$username = mysqli_real_escape_string($con, $username);
$password = mysqli_real_escape_string($con, $password);
$sql = "select *from userDetails where username = '$username' and password = '$password'";
$result = mysqli_query($con, $sql);
$row = mysqli_fetch_array($result, MYSQLI_ASSOC);
$count = mysqli_num_rows($result);
function function_alert($message) {
echo "<script>alert('$message');</script>";
}
if($count == 1){
session_regenerate_id();
$_SESSION['loggedin'] = TRUE;
header('Location: main.php');
}
else{
function_alert("Nesprávné heslo");
header("Location: https://blazeplay.eu/ktest/panel/test.html");
echo "Nesprávné přihlašovací údaje";
die();
}
?>
main.php(这是登录用户的主页)
<?php
include('auth.php');
$disUser = $username;
session_start();
if (!isset($_SESSION['loggedin'])) {
header('Location: test.html');
exit;
}
?>
还有一些 HTML...
非常感谢你帮助我。
解决方案
推荐阅读
- java - SpringData MongoDB查询嵌套对象和列表对象
- pandas - pandas 无法写入 Postgres db 抛出“KeyError: ("SELECT name FROM sqlite_master ..."
- java - Kafka Streams KeyValueStore 保留.bytes
- javascript - 如何从字符串中拆分日期时间并在对日期时间进行一些操作后我想将日期时间与此字符串动态连接
- angular - ionic 4从api获取动态更改工具栏背景颜色
- java - 如何使用 JWT Authentication 在 springboot 中使用 html 模板?
- postgresql - 为什么下面的代码不打折任何低于 9.99 的金额
- spring-boot - @CreatedBy 更新时变为空
- git - 我应该 git mv 还是只 mv 从另一个目录中挑选/变基的文件?
- python - 如何从我的数据库中为每个团队运行这个 api?