JohnOP Posted March 12, 2011 Share Posted March 12, 2011 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. Quote Link to comment Share on other sites More sharing options...
Scotty2024 Posted March 12, 2011 Share Posted March 12, 2011 You could set a cookie with past video IDs viewed. Or keep track of each video viewed by your users in a database. Do a check against the cookie/database before the video is loaded and if a match is found, send to a new random video. Quote Link to comment Share on other sites More sharing options...
JohnOP Posted March 12, 2011 Author Share Posted March 12, 2011 Hmm i have never used cookies i always use sessions, any chance of a bit of code on how to do this? Quote Link to comment Share on other sites More sharing options...
Scotty2024 Posted March 12, 2011 Share Posted March 12, 2011 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. Quote Link to comment Share on other sites More sharing options...
JohnOP Posted March 12, 2011 Author Share Posted March 12, 2011 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? Quote Link to comment Share on other sites More sharing options...
gizmola Posted March 13, 2011 Share Posted March 13, 2011 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)" Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.