代碼: 選擇全部
<?php
// 處理表單提交
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['dob_submit'])) {
$dob_input = $_POST['dob'] ?? '';
if (!empty($dob_input)) {
$dob = new DateTime($dob_input);
$today = new DateTime();
$age = $today->diff($dob)->y; // 計算滿幾歲
if ($age >= 18) {
// 滿 18 歲,寫入 Cookie(有效期限 30 天,請依需求調整)
setcookie('phpbb_age_verified', 'true', time() + (86400 * 30), '/');
// 重新整理頁面進入論壇
header('Location: ' . $_SERVER['REQUEST_URI']);
exit;
} else {
// 未滿 18 歲,跳轉至外部安全網站
header('Location: https://www.google.com');
exit;
}
}
}
?>
<!DOCTYPE html>
<html lang="zh-Hant">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>年齡驗證 - 本網站包含限制級內容</title>
<style>
body {
font-family: "Helvetica Neue", Arial, "PingFang TC", "Microsoft JhengHei", sans-serif;
background-color: #1a1a1a;
color: #ffffff;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
}
.verify-box {
background: #2a2a2a;
padding: 30px;
border-radius: 8px;
box-shadow: 0 4px 15px rgba(0,0,0,0.5);
text-align: center;
max-width: 400px;
width: 90%;
}
h2 { color: #ff4d4d; margin-top: 0; }
p { line-height: 1.6; color: #ccc; }
input[type="date"] {
padding: 10px;
font-size: 16px;
border-radius: 4px;
border: 1px solid #444;
margin: 15px 0;
width: 80%;
background: #333;
color: #fff;
}
button {
background-color: #d9534f;
color: white;
border: none;
padding: 10px 20px;
font-size: 16px;
border-radius: 4px;
cursor: pointer;
width: 85%;
}
button:hover { background-color: #c9302c; }
</style>
</head>
<body>
<div class="verify-box">
<h2>警告:年齡確認</h2>
<p>本網站內容包含限制級資訊,未滿 18 歲者不得進入。<br>請輸入您的出生年月日以進行驗證:</p>
<form method="POST" action="">
<input type="date" name="dob" required max="<?php echo date('Y-m-d'); ?>">
<br>
<button type="submit" name="dob_submit">確認進入</button>
</form>
</div>
</body>
</html>代碼: 選擇全部
<?php
/**
* 年齡驗證門檻機制
*/
if (!isset($_COOKIE['phpbb_age_verified']) || $_COOKIE['phpbb_age_verified'] !== 'true') {
require_once __DIR__ . '/age_verify.php';
exit; // 攔截後續 phpBB 程式執行
}
/**
*
* This file is part of the phpBB Forum Software package.
*
* @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*清除快取
sudo systemctl restart php8.5-fpm
sudo systemctl restart apache2