Jump to content

check if user viewed a page


JohnOP

Recommended Posts

Hello people i have a system that takes people to generated pages from the database, the user has a field to input a video and others watching videos will get redirecting to tht video in time, what i want to know is how can i tell if a user viewed the page so to stop them getting redirected to it again by my random video query?

 

The link always is video.php?id=blabla

 

the id changes every refresh, so i can call that id to check if there on the page but how can i tell if they have been on it before.

Link to comment
https://forums.phpfreaks.com/topic/230462-check-if-user-viewed-a-page/
Share on other sites

You could do it with sessions too.

 

To create a cookie use setcookie. For example: setcookie(name, value, expire, path, domain);

Then get the cookies data with $_COOKIE[]

It can be deleted by setting it to expire. For example setcookie("foo", "", time()-3600);

 

w3schools has a tutorial called What is a cookie?.

 

Both sessions and cookies will only temporarily keep track of the information for you. A database will keep track of it for as long as you want.

How would i be able to do it with the database though, if i add a table for all the videos when a user views the video i couldnt increment each video to know that he viewed it, i would have to have all the videos in his column so i can increment each seperate one would i not?

From a database point of view you would want a table that is related to the video table.  Let's assume that the video table has a video_id as the primary key.  I'll also assume your user table has a primary key of user_id.

 

This new table called videoview could be as simple as:

 

videoview_id int (PK, auto increment)

user_id

video_id

viewed_at timestamp

 

You simply need to enter a row when a user views a video.

 

Then you code up your query of random videos to include  "...WHERE NOT IN (SELECT video_id FROM videoview WHERE user_id = $user_id)"

 

 

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.