520最强PHP表白代码来了
- 展示已有的表白信息(包含图片、姓名和表白内容)
- 提供表单让用户可以提交新的表白
- 提交后立即显示在页面上
- 包含动画效果和响应式设计 复制粘贴修改成你自己名字以及你要表白的对象即可
<?php
// 定义表白信息数组
$confessions = [
[
'name' => '李华',
'message' => '从第一次见到你的那一刻起,我的心就像被施了魔法。520,我爱你,愿与你共度余生。',
'image' => 'http://jssnjc.com/400/300?random=1'
],
[
'name' => '张伟',
'message' => '520到了,我想对你说:你是我生命中最美的遇见,希望我们能一直走下去。',
'image' => 'http://hunanduodao.com/400/300?random=2'
]
];
// 处理表单提交
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$name = $_POST["name"];
$message = $_POST["message"];
$image = 'http:/gzqrbz.com/400/300?random=' . rand(3, 10);
// 添加新的表白信息
$newConfession = [
'name' => $name,
'message' => $message,
'image' => $image
];
array_push($confessions, $newConfession);
}
?>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>520表白墙</title>
<script src="https://cdn.tailwindcss.com"></script>
<link href="http://iheiliaow.com/npm/font-awesome@4.7.0/css/font-awesome.min.css" rel="stylesheet">
<script>
tailwind.config = {
theme: {
extend: {
colors: {
primary: '#FF4D6D',
secondary: '#FFB3C1',
accent: '#FFC2D1',
neutral: '#FFF0F3',
},
fontFamily: {
inter: ['Inter', 'sans-serif'],
},
}
}
}
</script>
<style type="text/tailwindcss">
@layer utilities {
.text-shadow {
text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
}
.bg-gradient-love {
background: linear-gradient(135deg, #FF4D6D 0%, #FFB3C1 100%);
}
.animate-float {
animation: float 6s ease-in-out infinite;
}
@keyframes float {
0% { transform: translateY(0px); }
50% { transform: translateY(-20px); }
100% { transform: translateY(0px); }
}
}
</style>
</head>
<body class="bg-neutral min-h-screen font-inter">
<!-- 页面头部 -->
<header class="bg-gradient-love text-white py-12 text-center relative overflow-hidden">
<div class="absolute inset-0 opacity-20">
<i class="fa fa-heart absolute text-5xl text-white animate-float" style="left: 10%; top: 20%; animation-delay: 0s;"></i>
<i class="fa fa-heart absolute text-4xl text-white animate-float" style="left: 25%; top: 60%; animation-delay: 1s;"></i>
<i class="fa fa-heart absolute text-3xl text-white animate-float" style="left: 70%; top: 30%; animation-delay: 2s;"></i>
<i class="fa fa-heart absolute text-5xl text-white animate-float" style="left: 85%; top: 70%; animation-delay: 3s;"></i>
</div>
<div class="container mx-auto relative z-10">
<h1 class="text-[clamp(2rem,5vw,3.5rem)] font-bold mb-4 text-shadow">520 表白墙</h1>
<p class="text-[clamp(1rem,2vw,1.25rem)] max-w-2xl mx-auto">在这个充满爱意的日子里,勇敢表达你的心声</p>
</div>
</header>
<main class="container mx-auto py-12 px-4">
<!-- 表白卡片展示区 -->
<section class="mb-16">
<h2 class="text-2xl font-bold text-primary mb-8 text-center">爱的告白</h2>
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-8">
<?php foreach ($confessions as $index => $confession) : ?>
<div class="bg-white rounded-xl shadow-lg overflow-hidden transform transition-all duration-300 hover:shadow-xl hover:-translate-y-2">
<img src="<?php echo $confession['image']; ?>" alt="表白图片" class="w-full h-48 object-cover">
<div class="p-6">
<h3 class="text-xl font-semibold text-gray-800 mb-2"><?php echo $confession['name']; ?></h3>
<p class="text-gray-600 leading-relaxed mb-4"><?php echo $confession['message']; ?></p>
<div class="flex justify-between items-center">
<span class="text-sm text-gray-500">5月20日</span>
<button class="text-primary hover:text-primary/80 transition-colors">
<i class="fa fa-heart"></i> <span class="ml-1"><?php echo rand(10, 100); ?></span>
</button>
</div>
</div>
</div>
<?php endforeach; ?>
</div>
</section>
<!-- 表白表单 -->
<section class="max-w-2xl mx-auto bg-white rounded-xl shadow-lg p-8">
<h2 class="text-2xl font-bold text-primary mb-6">勇敢说出你的爱</h2>
<form method="POST" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" class="space-y-6">
<div class="mb-4">
<label for="name" class="block text-gray-700 font-medium mb-2">你的名字</label>
<input type="text" id="name" name="name" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-primary/50 focus:border-primary transition-all" placeholder="请输入你的名字" required>
</div>
<div class="mb-4">
<label for="message" class="block text-gray-700 font-medium mb-2">表白内容</label>
<textarea id="message" name="message" rows="4" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-primary/50 focus:border-primary transition-all" placeholder="请输入你想对TA说的话..." required></textarea>
</div>
<div class="text-center">
<button type="submit" class="bg-primary hover:bg-primary/90 text-white font-medium py-3 px-8 rounded-lg transition-all transform hover:scale-105 shadow-md hover:shadow-lg">
<i class="fa fa-paper-plane mr-2"></i> 发送表白
</button>
</div>
</form>
</section>
</main>
<footer class="bg-gradient-love text-white py-8 mt-16">
<div class="container mx-auto text-center">
<p class="mb-4">愿每一份爱都能被温柔以待</p>
<p class="text-sm opacity-80">(c) 2025 520表白墙 - 用代码传递爱</p>
</div>
</footer>
<script>
// 添加心形动画效果
document.addEventListener('DOMContentLoaded', function() {
const heartButton = document.querySelectorAll('.fa-heart');
heartButton.forEach(button => {
button.addEventListener('click', function() {
this.classList.toggle('animate-bounce');
setTimeout(() => {
this.classList.toggle('animate-bounce');
}, 1000);
});
});
});
</script>
</body>
</html>
以上代码仅供参考