简体   繁体   中英

PHP check if user viewed specific page

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM