Hi, i am in the middle of developing a website, and i would like to add a function to my site whereby a member can see how many times their profile page has been viewed, similar to the way YouTube displays the amount of hits a video has. I have a few questions which i hope you can help me with: A - who does the YouTube counter work OR what is the best way to build these counters... are they (1) - IP based, (2) - Cookie based OR (3) - another method B - does the page make a database update each time a unique user lands on a video page C - how often is the number updated... for instance, if i view a video on youtube on several different devices all connected to different networks, the number does not update immediately... so how does it work Thanks in advance to anyone who can offer any help here
You might as well forget about how YouTube handles video view counts since that is NOT what you are looking to do. If you are just keeping track of profile views for your own members amusement and it doesn't play a critical role in any algorithms your web site may have you should count every literal load of the profile. I think your direction is skewed. You are asking questions about how YouTube keeps track of how many times a VIDEO is viewed yet you clearly stated you are looking to keep track of a view count of a web page.
Hi, thanks for your reply... i understand what you are saying, apologies for my poor analogy however i don't think it is right to just update $profile_views by +1 every time a users profile page is loaded as the hits will be inaccurate... as i don't want the hits to be +50 if a user simply refreshes a users profile by pressing refresh constantly... what approach would you consider then, thanks again for your reply...
YouTube's counter is a little more complex than simply IP or cookie based. YouTube frequently freezes the viewcount for hours on end while it investigates sources of traffic (presumably manually) to check for people trying to cheat the system, this is particularly important to them due to the nature of users earning revenue through their videos. You notice it most on videos with low viewcounts that get the reddit bump, they often end up with more likes on the video than views.
Yeah, i think youtube was a poor analogy I just need to record page views but don't want refreshes to be included etc...
First off... a profile view technically is a page view or impression regardless how many times a particular visitor views that profile. Obviously you are keeping track of views and not unique visitors correct? Again...IF the view count is ONLY for the members amusement and the accuracy is irrelevant to any other features on your web site it is not worth going through the extra steps to prevent "cheating" since there is no benefit to cheat other than increasing your view count for your own amusement. IF view count accuracy is vital to your web site than you have no choice but to come up with some sort of serverside and clientside method to prevent cheating and revisits. But it will never be accurate.
Use a session variable to increment the page count for a single session only once, no matter how many times the user returns to the page.
Hi, first off i do need to explain that this figure is important and does affect other elements of the site so i would like to make it as secure as possible... Hi, thanks for the reply... however, how would i control when their session would be open to constitute as a another hit, would it be possible to reset their session variable every 5 minutes... but that would probably effect other page hits then I remember Bebo had a profile counter too... and i figured out, if you landed on a profile page, that would constitute as +1 hit... however if you refreshed the profile page, nothing would happen, however if you clicked out into some other page on the site and then went back into the profile page, another +1 would count... i think this would be ideal, but not sure how to go about it... and the figures took a few hours to update also on Bebo...
As Rukbat suggested, I advise you use a session for the counter. In regards to expiring the session, here is an example: if (!isset($_SESSION['counter'])) { $_SESSION['counter'] = time(); // Code to increase counter by one (e.g. code to update counter in database) } else if (time() - $_SESSION['counter'] > 300) { //300 Seconds, which is 5 minutes. //Update counter after 5 minutes session_unset($_SESSION['counter']); // Destory time stamp $_SESSION['counter'] = time(); // reset time stamp // Code to increase counter by one (e.g. code to update counter in database) } Code (markup):
Sessions are about as secure as any other part of web technology. Absolutely secure? No, there's no such thing. But Davidson's code will do what you want.
Ok thanks guys, but how does the counter work for a specific page or is that session counter created for each profile page you visit, thanks for your help, much appreciated...
The session variable is created for the user's session. The counter is your choice - one for each page or one for the site. It depends on what you want to count.
I will Give you Cheap Youtube views upto 1000k =D If anyone want it Then contact me on skype skype = google_sale