登陆实例

-- deepseek r1 美化
This commit is contained in:
usami 2025-03-20 10:05:31 +08:00
parent 309efa4fd2
commit 20ad023eb9

245
login.php Normal file
View File

@ -0,0 +1,245 @@
<?php
const USER = 'admin';
const PASS = '123456';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$username = $_POST['username'] ?? '';
$password = $_POST['password'] ?? '';
$inputCaptcha = strtoupper($_POST['captcha'] ?? '');
$trueCaptcha = strtoupper($_POST['captcha_code'] ?? '');
$error = '';
if ($inputCaptcha !== $trueCaptcha) {
$error = '验证码错误';
} elseif ($username !== USER || $password !== PASS) {
$error = '账号或密码错误';
} else {
$error = '登录成功!';
}
}
function generateCaptcha() {
$chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
$captcha = substr(str_shuffle($chars), 0, 5);
$width = 120;
$height = 40;
$image = imagecreatetruecolor($width, $height);
$bgColor = imagecolorallocate($image, 255, 255, 255);
$textColor = imagecolorallocate($image, 0, 0, 0);
imagefilledrectangle($image, 0, 0, $width, $height, $bgColor);
imagestring($image, 5, 30, 12, $captcha, $textColor);
ob_start();
imagepng($image);
$imgData = ob_get_clean();
imagedestroy($image);
return [
'code' => $captcha,
'image' => 'data:image/png;base64,' . base64_encode($imgData)
];
}
$captchaData = generateCaptcha();
?>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>系统登录 - 安全入口</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}
body {
min-height: 100vh;
display: flex;
justify-content: center;
align-items: center;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}
.login-container {
background: rgba(255, 255, 255, 0.95);
padding: 2.5rem;
border-radius: 1rem;
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
width: 100%;
max-width: 400px;
transform: translateY(-10%);
}
h2 {
text-align: center;
color: #2d3748;
margin-bottom: 1.8rem;
font-size: 1.8rem;
}
.form-group {
margin-bottom: 1.5rem;
}
label {
display: block;
margin-bottom: 0.5rem;
color: #4a5568;
font-weight: 600;
}
input {
width: 100%;
padding: 0.8rem;
border: 2px solid #e2e8f0;
border-radius: 0.5rem;
font-size: 1rem;
transition: border-color 0.3s ease;
}
input:focus {
outline: none;
border-color: #667eea;
box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}
.captcha-group {
display: flex;
gap: 1rem;
align-items: center;
}
.captcha-img {
border-radius: 0.5rem;
border: 2px solid #e2e8f0;
cursor: pointer;
transition: transform 0.2s ease;
}
.captcha-img:hover {
transform: scale(1.05);
}
button {
width: 100%;
padding: 1rem;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
border: none;
border-radius: 0.5rem;
font-size: 1rem;
font-weight: 600;
cursor: pointer;
transition: transform 0.2s ease, opacity 0.2s ease;
}
button:hover {
transform: translateY(-2px);
opacity: 0.9;
}
.error {
padding: 1rem;
margin-bottom: 1.5rem;
background: #fff5f5;
color: #c53030;
border: 2px solid #fed7d7;
border-radius: 0.5rem;
font-weight: 500;
display: flex;
align-items: center;
gap: 0.8rem;
}
.error::before {
content: '!';
display: flex;
align-items: center;
justify-content: center;
width: 1.5rem;
height: 1.5rem;
background: #c53030;
color: white;
border-radius: 50%;
font-weight: bold;
}
.success {
background: #f0fff4;
color: #2f855a;
border-color: #c6f6d5;
}
.success::before {
content: '✓';
background: #48bb78;
}
</style>
</head>
<body>
<div class="login-container">
<h2>系统安全登录</h2>
<?php if (!empty($error)): ?>
<div class="error <?= strpos($error, '成功') !== false ? 'success' : '' ?>">
<?= $error ?>
</div>
<?php endif; ?>
<form method="post">
<div class="form-group">
<label for="username">账号</label>
<input
type="text"
id="username"
name="username"
required
placeholder="请输入您的账号"
>
</div>
<div class="form-group">
<label for="password">密码</label>
<input
type="password"
id="password"
name="password"
required
placeholder="请输入您的密码"
>
</div>
<div class="form-group">
<label>验证码</label>
<div class="captcha-group">
<input
type="text"
name="captcha"
required
placeholder="输入右侧验证码"
style="flex: 1;"
>
<img
src="<?= $captchaData['image'] ?>"
class="captcha-img"
title="点击刷新验证码"
onclick="this.src='<?= $captchaData['image'] ?>?t='+Date.now()"
>
<input type="hidden" name="captcha_code" value="<?= $captchaData['code'] ?>">
</div>
</div>
<button type="submit">立即登录</button>
</form>
</div>
</body>
</html>