PHP检查用户是否查看了特定页面

问题描述:

I am currently building web app in PHP where the client wants to have logged in users. There will be hierarchy so the new users won't have priviliges as higher positioned users. The priviliged users will be able to post articles and files for users to see.

This is my question: How can adminisitrator or the privileged user check who viewed the article or downloaded the files. Is this possible via PHP?

我目前正在PHP中构建Web应用程序,客户端希望登录用户。 将存在层次结构,因此新用户将不具有作为更高定位用户的特权。 特权用户将能够发布文章和文件供用户查看。 p>

这是我的问题:管理员或特权用户如何查看谁查看了文章或下载了文件。 这可以通过PHP吗? p> div>

Of course it's possible, but you won't get it out of the box most likely. You'll need to store the access history for any given user server-side. You could do this by simply storing user ids, urls, and times in a seperate table in your database. Something along the lines of:

 5 | '/filedownload.php?file=cake-instructions.php' | 2012-02-15 08:23:11
 8 | '/company-information'                         | 2012-02-15 08:15:01

Anytime a user accesses a url, you store their id, that url, and the current time in a database. This would then be readily accessible to administrators if they want to perform queries to see who viewed what, and when.

Assuming you have a table named Article, you can store a variable in that table, lets say nr_of_views. Each time a user views an article/page, take the id of the article and increment the nr_of_views variable. Something like that.