🗣 Wd提问: PHP源码签到系统
🤖 Ai回答: PHP签到系统实现
下面是一个完整的PHP签到系统实现,包含用户注册、登录、签到和查看签到记录等功能。
数据库结构
首先需要创建数据库和表结构:
sql
CREATE DATABASE IF NOT EXISTS checkin_system;
USE checkin_system;
CREATE TABLE IF NOT EXISTS users (
id INT AUTO_INCREMENT PRIMARY KEY,
username VARCHAR(50) NOT NULL UNIQUE,
password VARCHAR(255) NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE IF NOT EXISTS checkins (
id INT AUTO_INCREMENT PRIMARY KEY,
user_id INT NOT NULL,
checkin_date DATE NOT NULL,
checkin_time TIME NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (user_id) REFERENCES users(id)
);
系统文件结构
签到系统/
├── db.php 数据库连接
├── index.php 首页(重定向到登录页)
├── register.php 用户注册
├── login.php 用户登录
├── checkin.php 签到页面
├── records.php 签到记录
└── logout.php 退出登录
1、数据库连接文件 (db.php)
php
<?php
session_start();
$host = 'localhost';
$db = 'checkin_system';
$user = 'root'; // 根据实际修改
$pass = ''; // 根据实际修改
$charset = 'utf8mb4';
$dsn = mysql:host=$host;dbname=$db;charset=$charset;
$options = [
PDO::ATTR_ERRMODE = PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE = PDO::FETCH_ASSOC,
PDO::ATTR_EMULATE_PREPARES = false,
];
try {
$pdo = new PDO($dsn, $user, $pass, $options);
} catch (\PDOException $e) {
die(数据库连接失败: 、$e-getMessage());
}
?
2、用户注册 (register.php)
php
<?php
require 'db.php';
$error = '';
$success = '';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$username = trim($_POST['username']);
$password = $_POST['password'];
$confirm_password = $_POST['confirm_password'];
if (empty($username) empty($password) empty($confirm_password)) {
$error = '所有字段都是必填的。';
} elseif ($password !== $confirm_password) {
$error = '密码不匹配。';
} elseif (strlen($password) < 6) {
$error = '密码至少需要6个字符。';
} else {
// 检查用户名是否已存在
$stmt = $pdo-prepare(SELECT id FROM users WHERE username = ?);
$stmt-execute([$username]);
if ($stmt-rowCount() 0) {
$error = '用户名已存在。';
} else {
// 创建新用户
$hashed_password = password_hash($password, PASSWORD_DEFAULT);
$stmt = $pdo-prepare(INSERT INTO users (username, password) VALUES (?, ?));
if ($stmt-execute([$username, $hashed_password])) {
$success = '注册成功!现在可以登录。';
} else {
$error = '注册失败,请重试。';
}
}
}
}
?
<!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
* {
box-sizing: border-box;
margin: 0;
padding: 0;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}
body {
background: linear-gradient(135deg, 667eea, 764ba2);
min-height: 100vh;
display: flex;
justify-content: center;
align-items: center;
padding: 20px;
}
.container {
width: 100%;
max-width: 450px;
background-color: white;
border-radius: 10px;
box-shadow: 0 15px 30px rgba(0, 0, 0, 0.2);
overflow: hidden;
}
.header {
background: linear-gradient(to right, 4b6cb7, 182848);
color: white;
padding: 25px;
text-align: center;
}
.header h1 {
font-size: 28px;
margin-bottom: 10px;
}
.header p {
opacity: 0.8;
font-size: 16px;
}
.form-container {
padding: 30px;
}
.form-group {
margin-bottom: 25px;
}
label {
display: block;
margin-bottom: 8px;
font-weight: 600;
color: 2d3748;
}
input {
width: 100%;
padding: 14px;
border: 1px solid e2e8f0;
border-radius: 6px;
font-size: 16px;
transition: border-color 0.3s;
}
input:focus {
outline: none;
border-color: 4b6cb7;
box-shadow: 0 0 0 3px rgba(75, 108, 183, 0.2);
}
.error {
color: e53e3e;
background-color: fff5f5;
padding: 12px;
border-radius: 6px;
margin-bottom: 20px;
border: 1px solid fed7d7;
}
.success {
color: 276749;
background-color: f0fff4;
padding: 12px;
border-radius: 6px;
margin-bottom: 20px;
border: 1px solid c6f6d5;
}
button {
background: linear-gradient(to right, 4b6cb7, 182848);
color: white;
border: none;
width: 100%;
padding: 14px;
border-radius: 6px;
font-size: 16px;
font-weight: 600;
cursor: pointer;
transition: all 0.3s;
}
button:hover {
transform: translateY(-2px);
box-shadow: 0 5px 15px rgba(75, 108, 183, 0.4);
}
.link {
text-align: center;
margin-top: 20px;
color: 4a5568;
}
.link a {
color: 4b6cb7;
text-decoration: none;
font-weight: 600;
transition: color 0.3s;
}
.link a:hover {
color: 182848;
text-decoration: underline;
}
</style
</head
<body
<div class=container
<div class=header
<h1签到系统</h1
<p记录您的每日签到</p
</div
<div class=form-container
<h2 style=margin-bottom: 20px; color: 2d3748;创建新账户</h2
<?php if ($error): ?
<div class=error<?php echo $error; ?</div
<?php endif; ?
<?php if ($success): ?
<div class=success<?php echo $success; ?</div
<?php endif; ?
<form method=post action=register.php
<div class=form-group
<label for=username用户名</label
<input type=text id=username name=username required
placeholder=请输入用户名 autocomplete=off
</div
<div class=form-group
<label for=password密码</label
<input type=password id=password name=password required
placeholder=至少6个字符
</div
<div class=form-group
<label for=confirm_password确认密码</label
<input type=password id=confirm_password name=confirm_password required
placeholder=请再次输入密码
</div
<button type=submit注册</button
</form
<div class=link
已有账号? <a href=login.php登录</a
</div
</div
</div
</body
</html
3、用户登录 (login.php)
📣 商家广告 :
👍
0
👎
IP地址: 45.102.123.55
搜索次数: 5
提问时间: 2025-11-05 22:24:04
🛒 域名购买 :
80.gs zhanwai.cn 373.net.cn 9.gz.cn 76.plus a-s.cn 757.net.cn sktq.cn ww.js.cn 81.biz
❓️ 热门提问 :
.org域名申请 神器挂机 带宽 云主机 虚拟主机 长春 香港地区的vps vps 新加坡服务器 私人日本vps shia域名 2500左右的电脑主机 虚拟空间应用程序 豌豆Ai站群搜索引擎系统
🌐 域名评估 :
q.sx.cn uskm.cn su8.js.cn vv.he.cn pp.sd.cn vtol.sh.cn 71.cx ijuwo.com mnbj.cn kjgi.cn
⛏ 最新挖掘 :
凯里酸汤鱼 贵阳烤脑花 都匀毛尖茶 花溪牛肉粉 贵阳烤生蚝 贵阳烤豆腐 贵阳纸包鱼 贵阳特色菜
🖌 热门作画 :
🤝 关于我们:
豌豆Ai
域名
建站
站群
留痕
推广
评估
源码
开发Ai
工具
日记
价格
加盟
广告
流量
留言
联系
🗨 加入群聊 :
🔗 友情链接 :
广州南沙月饼厂
贵阳电工维修电话
ai提问
🧰 站长工具 :Ai工具 whois查询 搜索
📢 温馨提示 :本站所有问答由Ai自动创作,内容仅供参考,若有误差请用“联系”里面信息通知我们人工修改或删除。
👉 技术支持 :本站由豌豆Ai 提供技术支持,使用的最新版:《豌豆Ai站群搜索引擎系统 V.25.10.25》搭建本站。