Correcting teacher:PHPz
Correction status:qualified
Teacher's comments:
async function doLogin(obj){
const email = obj.form.email.value;
const password = obj.form.password.value;
if (email.length > 0 && password.length > 0){
const response = await fetch('./lib/user/handle.php', {
method:'POST',
headers: {
'Content-type':'application/json;charset=utf-8'
},
body:JSON.stringify({
email,
password}),
});
const result = await response.json();
if(result){
alert('登录成功!');
location.href = 'index.php';
}else{
alert('验证失败!');
location.href = 'login.php';
}
}
}
session_start();
$users = require __DIR__. '/../../data/user.php';
$json = file_get_contents('php://input');
$newUser = json_decode($json, true);
$salt = 'dmegc';
$email = $newUser['email'];
$password = md5($salt . $newUser['password']);
$newArr2 = array_values(array_filter([1,2,3,4,5,6], function($item){
return $item%2==0;
}));
$result = array_values(array_filter($users, function($user) use ($email, $password){
return $user['password'] === $password && $user['email'] === $email;
}));
$flag = false;
if(count($result)===1){
$flag = true;
$_SESSION['name'] = $result[0]['name'];
}
echo json_encode($flag);
<a href="login.php"><?php echo isset($_SESSION['name'])?$_SESSION['name'].'注销':'登录/注册'?></a>
挺简单的内容,可以讲的快一点;留出时间多实战。