把按钮去除插入个需要开通VIP继续使用完整版代码php 判断是否已经开启了 sessionif session_status !== PHP_SESSION_ACTIVE session_start; 自定义访问次数这里设置为 5 次$limit = 50;if isset$_SESSIONcount $_SESSIONcount++; else $_SESSIONcoun
<?php
// 判断是否已经开启了 session
if (session_status() !== PHP_SESSION_ACTIVE) {
session_start();
}
// 自定义访问次数,这里设置为 5 次
$limit = 50;
if (isset($_SESSION['count'])) {
$_SESSION['count']++;
} else {
$_SESSION['count'] = 1;
}
$count = $limit - $_SESSION['count'];
// 如果访问次数超过了限制,跳转到开通 VIP 页面
if ($count <= 0) {
header("Location: https://example.com/vip");
exit;
}
?>
<!DOCTYPE html>
<html>
<head>
<title>限制访问次数</title>
<meta charset="utf-8">
<style>
.progress {
width: 300px;
height: 20px;
background-color: #f2f2f2;
border-radius: 10px;
margin-bottom: 30px;
}
<pre><code> .progress-bar {
height: 100%;
background-color: #4CAF50;
border-radius: 10px;
text-align: center;
line-height: 20px;
color: white;
}
</style>
</code></pre>
</head>
<body>
<h1>欢迎访问本页面</h1>
<p>您还可以访问 <?php echo $count; ?> 次</p>
<pre><code><div class="progress">
<div class="progress-bar" style="width: <?php echo $count * (100 / $limit); ?>%">
<?php echo $count; ?>
</div>
</div>
<a href="https://example.com/vip">开通 VIP 继续使用</a>
</code></pre>
</body>
</html>
原文地址: https://www.cveoy.top/t/topic/1Qd 著作权归作者所有。请勿转载和采集!