File tree Expand file tree Collapse file tree 1 file changed +12
-17
lines changed
Expand file tree Collapse file tree 1 file changed +12
-17
lines changed Original file line number Diff line number Diff line change 11<?php
2- session_start () ;
2+ require ' config.php ' ;
33
44if ($ _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?>
You can’t perform that action at this time.
0 commit comments