Clean Code
This commit is contained in:
parent
16c549b7cb
commit
309efa4fd2
23
auth.php
23
auth.php
@ -13,11 +13,10 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
if (isset($users[$user]) && $users[$user] === $pass) {
|
||||
$_SESSION['user'] = $user;
|
||||
} else {
|
||||
$error = "登录失败";
|
||||
$error = "Retcode : 0";
|
||||
}
|
||||
}
|
||||
|
||||
// 处理退出
|
||||
if (isset($_GET['logout'])) {
|
||||
unset($_SESSION['user']);
|
||||
}
|
||||
@ -26,7 +25,7 @@ if (isset($_GET['logout'])) {
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh_CN">
|
||||
<head>
|
||||
<title>极简登录</title>
|
||||
<title>Login For Nothing</title>
|
||||
<style>
|
||||
.box { width: 300px; margin: 100px auto; padding: 20px; border: 1px solid #ccc; }
|
||||
input { margin: 5px 0; padding: 8px; width: 95%; }
|
||||
@ -36,29 +35,23 @@ if (isset($_GET['logout'])) {
|
||||
<body>
|
||||
<?php if (isset($_SESSION['user'])): ?>
|
||||
<div class="box">
|
||||
<h2>欢迎 <?php echo $_SESSION['user'] ?>!</h2>
|
||||
<a href="?logout">退出登录</a>
|
||||
<h2>Welcome <?php echo $_SESSION['user'] ?>!</h2>
|
||||
<a href="?logout">Log out</a>
|
||||
</div>
|
||||
<?php else: ?>
|
||||
<div class="box">
|
||||
<h2>用户登录</h2>
|
||||
<h2>Login</h2>
|
||||
<?php if (isset($error)) echo "<p style='color:red'>$error</p>" ?>
|
||||
|
||||
<form method="POST">
|
||||
<label>
|
||||
<input type="text" name="username" placeholder="用户名" required>
|
||||
<input type="text" name="username" placeholder="Username" required>
|
||||
</label><br>
|
||||
<label>
|
||||
<input type="password" name="password" placeholder="密码" required>
|
||||
<input type="password" name="password" placeholder="Password" required>
|
||||
</label><br>
|
||||
<button type="submit">登录</button>
|
||||
<button type="submit">Login</button>
|
||||
</form>
|
||||
|
||||
<p style="margin-top:15px;color:#666">
|
||||
测试账号:<br>
|
||||
admin / 123456<br>
|
||||
guest / abc123
|
||||
</p>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</body>
|
||||
|
Loading…
Reference in New Issue
Block a user