squiblo Posted January 7, 2012 Share Posted January 7, 2012 What is the best way to store "page view count", the page view count will increment by 1 if the users IP address is not already stored. I want to plan for the future in case i start to get a lot of visits, what is your opinion for the best way to do this and why? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/254570-page-view-count/ Share on other sites More sharing options...
trq Posted January 7, 2012 Share Posted January 7, 2012 http://www.google.com/analytics/ Quote Link to comment https://forums.phpfreaks.com/topic/254570-page-view-count/#findComment-1305396 Share on other sites More sharing options...
squiblo Posted January 7, 2012 Author Share Posted January 7, 2012 thorpe, it's not a feature to analyse my website but more of a feature like youtube views. Quote Link to comment https://forums.phpfreaks.com/topic/254570-page-view-count/#findComment-1305398 Share on other sites More sharing options...
scootstah Posted January 7, 2012 Share Posted January 7, 2012 Here's a really simple solution: CREATE TABLE `pageview` ( `user_ip` int(11) NOT NULL, PRIMARY KEY (`user_ip`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 // insert $query = mysql_query("REPLACE INTO pageview (user_ip) VALUES ('" . ip2long($_SERVER['REMOTE_ADDR']) . "')"); // retrieve list($pageviews) = mysql_fetch_row(mysql_query("SELECT COUNT(user_ip) FROM pageview")); echo $pageviews; Quote Link to comment https://forums.phpfreaks.com/topic/254570-page-view-count/#findComment-1305400 Share on other sites More sharing options...
squiblo Posted January 7, 2012 Author Share Posted January 7, 2012 Thanks scootstah, that's what I had in mind but I have a little doubt in my mind with this solution. My website will have dynamic pages (like youtube, adding videos). If I have 1000 "pages" and 10,000 users each visit all of these pages (I know these figures are not true, but I'm trying to plan ahead) that will equal 10,000,000 rows. Something tells me that isn't going to be good, but I have no real evidence to back up my thinking. Is this a problem? Quote Link to comment https://forums.phpfreaks.com/topic/254570-page-view-count/#findComment-1305402 Share on other sites More sharing options...
scootstah Posted January 7, 2012 Share Posted January 7, 2012 No it won't. It will only insert a new row if one doesn't already exist. Read: http://dev.mysql.com/doc/refman/5.0/en/replace.html EDIT: Wait, nevermind...I see what you mean. 10,000 rows is really diddly in a database. This forum alone has well over 1 million rows just for posts. EDIT 2: Oh god, I can't read today. 10 million...right. Quote Link to comment https://forums.phpfreaks.com/topic/254570-page-view-count/#findComment-1305405 Share on other sites More sharing options...
squiblo Posted January 7, 2012 Author Share Posted January 7, 2012 10,000,000 rows, not 10,000. Thanks for that REPLACE, never seen it before! Quote Link to comment https://forums.phpfreaks.com/topic/254570-page-view-count/#findComment-1305407 Share on other sites More sharing options...
scootstah Posted January 7, 2012 Share Posted January 7, 2012 If you want unique visits (by checking an IP) then unfortunately you have to deal with this. If potentially fake views aren't a problem then you can simply increment the view on every page load. I think most sites use this method, including Youtube. Quote Link to comment https://forums.phpfreaks.com/topic/254570-page-view-count/#findComment-1305408 Share on other sites More sharing options...
squiblo Posted January 7, 2012 Author Share Posted January 7, 2012 Thanks scootstah, I think I'm going to use a mixture of IP addresses, UserID's and cookies for people that are logged in and people that are logged out. Quote Link to comment https://forums.phpfreaks.com/topic/254570-page-view-count/#findComment-1305409 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.