【发布时间】:2020-05-06 09:02:51
【问题描述】:
我有一个代码可以计算用户访问页面的次数。当有人第 5 次访问时,我试图显示一条特殊消息。
<?php
session_start();
if (empty($_SESSION['count'])) {
$_SESSION['count'] = 1;
} if($_SESSION['count'] === 5){
echo '<p> This is your' . $_SESSION['count'] . 'th time! Glad to have you back! </p>';
}if($_SESSION['count'] === 10) {
echo '<p> This is your' . $_SESSION['count'] . 'th time! You must love it here</p>';
}if($_SESSION['count'] === 20){
echo '<p> Hi again, this is your' . $_SESSION['count'] . 'th time! This will restart the page. Thanks for visiting so much! </p>';
$_SESSION['count'] = 0;
} else {
$_SESSION['count']++;
}
?>
<p> Hello Visitor! You have seen this page <?php echo $_SESSION['count'];?> times!</p>
【问题讨论】:
-
您的问题或问题是什么?
-
我正在尝试最多跟踪 20 个访客,然后重置计数器。我有代码,但是当我运行时,我得到了这个。它似乎在跟踪 1,我不知道为什么.. 这是你的第 10 次!你一定喜欢这里你好访客!你已经看过这个页面 11 次了!
-
这是你第十次了!你一定喜欢这里你好访客!你已经看过这个页面 11 次了!
-
您应该使用当前代码更新您的问题。
-
好的,我更新了!让我知道你是否能帮我弄清楚为什么它的跟踪落后..