noobstar Posted January 6, 2007 Share Posted January 6, 2007 Hi there :)How would it be possible to uniquely increment the count of how many times a thread in a forum is being viewed?I'll take a wild guess, is it something to do with the IP addresses?thanks for any help what so ever :) Quote Link to comment https://forums.phpfreaks.com/topic/33075-solved-topic-view-count/ Share on other sites More sharing options...
.josh Posted January 6, 2007 Share Posted January 6, 2007 yes. but fyi, it's not 100% accurate. Quote Link to comment https://forums.phpfreaks.com/topic/33075-solved-topic-view-count/#findComment-154124 Share on other sites More sharing options...
noobstar Posted January 6, 2007 Author Share Posted January 6, 2007 Hmmm im guessing there is a better way or ?Let me know which ever way is possible i will give it a go and see which one would suit it bestthanks for the fast reply ^_^ Quote Link to comment https://forums.phpfreaks.com/topic/33075-solved-topic-view-count/#findComment-154125 Share on other sites More sharing options...
invincible_virus Posted January 6, 2007 Share Posted January 6, 2007 may be u can try using [b]session id[/b] Quote Link to comment https://forums.phpfreaks.com/topic/33075-solved-topic-view-count/#findComment-154134 Share on other sites More sharing options...
.josh Posted January 6, 2007 Share Posted January 6, 2007 session id's wouldn't really work. Random Joe goes to your site and views the page, and you start a session, it only prevents the counter from incrementing as long as he's at your site, or even has the browser open. But as soon as he closes it, the session expires. Joe comes back to your site, gets assigned a new session id, and bam, he's another unique visitor. The only [i]more[/i] accurate way is if the only way a user can view the page is if the user is logged in. Then you can keep track of whether each user has viewed the topic or not. But really, that's a whole lot of useless data buildup. If you have 1,000 users and 1,000 topics that's up to 1,000,000 rows in a table to keep track of whether the view was unique or not. And 1,000 users and 1,000 topics is a drop in a bucket. And again, that's assuming you only want to make the topics only viewable by logged in members. Keeping a list of IP addresses to find out unique views does leave a margin of error, as peoples' IP address change all the time, but it's an acceptable tradeoff. What you can also do to narrow that margin is to set a cookie and have your script check for it. Some people don't allow cookies, so again, it's not a 100% thing, but a lot of people do allow cookies, so it should help narrow the margin. You could also force cookies on the user. That is, have your script try to make a cookie and if it fails, give a message to the user that they can't view your site without enabling cookies. Then, you can have your counter only increment if it doesn't find a cookie initially. This may or may not be a desirable thing, though. Just keep in mind that simply keeping a list of ip addresses and checking for a cookie (but not forcing it) does leave an acceptable margin of error for most professional sites. It really depends on the nature of your site, what type of people your expected visitors are, and how your site is setup in the first place, etc.. as to what really is the most efficient way to go about this is. Quote Link to comment https://forums.phpfreaks.com/topic/33075-solved-topic-view-count/#findComment-154280 Share on other sites More sharing options...
noobstar Posted January 7, 2007 Author Share Posted January 7, 2007 thanks a lot mate you helped me out a great deal i will give the cookies a go if not i'll just get it to increment every time a user just clicks on the page .. it ain't a unique visit but i guess it has to do.thanks again this has been puzzling me for some time :) Quote Link to comment https://forums.phpfreaks.com/topic/33075-solved-topic-view-count/#findComment-154852 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.