Skip to content

Commit cf38f0d

Browse files
authored
Update login.php
1 parent 6b1850e commit cf38f0d

File tree

1 file changed

+12
-17
lines changed

1 file changed

+12
-17
lines changed

denlu/login.php

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,21 @@
11
<?php
2-
session_start();
2+
require 'config.php';
33

44
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
5-
// 简单的用户存储(在实际项目中应使用数据库)
6-
$users = isset($_SESSION['users']) ? $_SESSION['users'] : array();
7-
85
$email = $_POST['email'];
96
$password = $_POST['password'];
10-
11-
// 查找用户
12-
foreach ($users as $user) {
13-
if ($user['email'] == $email && $user['password'] == $password) {
14-
$_SESSION['user'] = $user;
15-
echo '登录成功';
16-
exit();
17-
}
7+
8+
$stmt = $db->prepare('SELECT * FROM users WHERE email = :email');
9+
$stmt->bindValue(':email', $email, SQLITE3_TEXT);
10+
$result = $stmt->execute();
11+
$user = $result->fetchArray(SQLITE3_ASSOC);
12+
13+
if ($user && password_verify($password, $user['password'])) {
14+
echo '登录成功';
15+
} else {
16+
echo '邮箱或密码错误';
1817
}
19-
20-
echo '邮箱或密码无效';
2118
} else {
22-
// 返回405错误
23-
http_response_code(405);
24-
echo '方法不允许';
19+
echo '无效的请求方法';
2520
}
2621
?>

0 commit comments

Comments
 (0)