Jump to content

Page view count


squiblo

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/254570-page-view-count/
Share on other sites

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;

Link to comment
https://forums.phpfreaks.com/topic/254570-page-view-count/#findComment-1305400
Share on other sites

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?

Link to comment
https://forums.phpfreaks.com/topic/254570-page-view-count/#findComment-1305402
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/254570-page-view-count/#findComment-1305405
Share on other sites

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.