<?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;
    }
&lt;/style&gt;
</code></pre>
</head>
<body>
    <h1>欢迎访问本页面</h1>
    <p>您还可以访问 <?php echo $count; ?> 次</p>
<pre><code>&lt;div class=&quot;progress&quot;&gt;
    &lt;div class=&quot;progress-bar&quot; style=&quot;width: &lt;?php echo $count * (100 / $limit); ?&gt;%&quot;&gt;
        &lt;?php echo $count; ?&gt;
    &lt;/div&gt;
&lt;/div&gt;

&lt;a href=&quot;https://example.com/vip&quot;&gt;开通 VIP 继续使用&lt;/a&gt;
</code></pre>
</body>
</html>
把按钮去除插入个需要开通VIP继续使用完整版代码php 判断是否已经开启了 sessionif session_status !== PHP_SESSION_ACTIVE session_start; 自定义访问次数这里设置为 5 次$limit = 50;if isset$_SESSIONcount $_SESSIONcount++; else $_SESSIONcoun

原文地址: https://www.cveoy.top/t/topic/1Qd 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录