如何在每个页面加载时增加计数器(在PHP中)? [英] How to increment a counter each page load (in PHP)?
本文介绍了如何在每个页面加载时增加计数器(在PHP中)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当用户访问网站的X页时,我希望采取某种措施
I want a certain action to happen when a user has visited X pages of a site
我是否必须将计数器存储在外部(在txt文件或db中)?
Do I have to store the counter externally (in a txt file or db)?
我想不出一种方法来将计数器设置为0,然后在每次页面加载时将其递增。计数器总是会重置为0,还是我遗漏了一些明显的东西?
I can't think of a way to set the counter to 0, then increment it each page load. The counter would always get reset to 0, or am I missing something obvious?
推荐答案
仅使用 $ _ SESSION
数据来存储个人查看过多少页面。
It would be pretty simple to just use $_SESSION
data to store how many pages an individual has viewed.
$_SESSION['pageviews'] = ($_SESSION['pageviews']) ? $_SESSION['pageviews'] + 1 : 1;
这篇关于如何在每个页面加载时增加计数器(在PHP中)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文