Rommeo Posted November 5, 2009 Share Posted November 5, 2009 There are many pages in my website, I want to store the hit(viewed) of the pages in DB, so I can show "most viewed pages" at right column. How can I do this ? I was going to put an insert query of showpage.php file, but I don't know if this is the correct way. Thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/180351-solved-counting-the-pageview/ Share on other sites More sharing options...
Jnerocorp Posted November 5, 2009 Share Posted November 5, 2009 so you want a database with tablename: *pageviews fields: *hits *url so it adds 1+ view to hits each time page loads and it adds it to the url of whatever page the script is on so that it adds a hit to the correct page so later you can select hits where url="$url" and then order it by most hits to least? -John Quote Link to comment https://forums.phpfreaks.com/topic/180351-solved-counting-the-pageview/#findComment-951392 Share on other sites More sharing options...
Rommeo Posted November 5, 2009 Author Share Posted November 5, 2009 so you want a database with tablename: *pageviews fields: *hits *url so it adds 1+ view to hits each time page loads and it adds it to the url of whatever page the script is on so that it adds a hit to the correct page so later you can select hits where url="$url" and then order it by most hits to least? -John I do not know if this is the correct way but I was going to make my database like pages id || title || content || hits(pageview) and yes you got me correct. Quote Link to comment https://forums.phpfreaks.com/topic/180351-solved-counting-the-pageview/#findComment-951394 Share on other sites More sharing options...
gizmola Posted November 5, 2009 Share Posted November 5, 2009 Why would you want to reinvent the wheel, not to mention add considerable load to your database, when there are numerous log analysis products out there? Don't get me wrong -- I have used internal logging many times, but never just to have something that comes easily from the logs. Your list of pages will come right out of the log analysis. Quote Link to comment https://forums.phpfreaks.com/topic/180351-solved-counting-the-pageview/#findComment-951396 Share on other sites More sharing options...
Rommeo Posted November 5, 2009 Author Share Posted November 5, 2009 Why would you want to reinvent the wheel, not to mention add considerable load to your database, when there are numerous log analysis products out there? Don't get me wrong -- I have used internal logging many times, but never just to have something that comes easily from the logs. Your list of pages will come right out of the log analysis. That's why I m here, as I said I have no idea about how people count the number of pageviews easily. As I m a newbie, I would be glad if you could explain me the meaning of "when there are numerous log analysis products out there". Where ? any example ? what should I use the count the hits of my pages ? Quote Link to comment https://forums.phpfreaks.com/topic/180351-solved-counting-the-pageview/#findComment-951402 Share on other sites More sharing options...
waynew Posted November 5, 2009 Share Posted November 5, 2009 Use Google Analytics, it's free. Quote Link to comment https://forums.phpfreaks.com/topic/180351-solved-counting-the-pageview/#findComment-951423 Share on other sites More sharing options...
colap Posted November 5, 2009 Share Posted November 5, 2009 Does this work?(using textfile) http://www.plus2net.com/php_tutorial/php_counters.php Quote Link to comment https://forums.phpfreaks.com/topic/180351-solved-counting-the-pageview/#findComment-951427 Share on other sites More sharing options...
gizmola Posted November 5, 2009 Share Posted November 5, 2009 So first a comment on terminology: A "hit" is generally understood to mean a request to the web server. Pages are made up of many requests. So the generally used term to mean "an entire page" is a "pageview". For logging there are many different ways to go. You can outsource things to google by signing up for google analytics and including their counter. This might be good enough for you, and the reporting is very flexible. The main knock against this is that it will probably undercount things, and it depends on google's servers, so if there's any latency issue that might be a problem. Also it depends on you adding their code in all your pages, which might be easy, or time consuming depending on how your site is constructed. So -- here's the ones that are primarily used: http://awstats.sourceforge.net/ http://www.mrunix.net/webalizer/ There is a php/mysql based hybrid analyzer you can run on your own server, but otherwise looks and acts a lot like google analytics. It's a lot prettier than awstats and webalizer, although it really isn't doing anything different than what they do. With that said, I do use an older version of it on my blog. http://piwik.org/ It has the same issues I raised about load, whereas webalizer and awstats work on the raw web logs of your server. In this case, both for completeness, and because you stated that you're a newbie, I thought I should include it for consideration. Out of the 3, all have setup issues associated with them, unless you're on a hosted server. In my experience most hosted servers offer awstats and/or webalizer out of the box. You just have to know where to look for them, and sometimes turn them on. Configuring either one can be quite an exercise unfortunately. Quote Link to comment https://forums.phpfreaks.com/topic/180351-solved-counting-the-pageview/#findComment-951432 Share on other sites More sharing options...
Rommeo Posted November 5, 2009 Author Share Posted November 5, 2009 Thank you all for your answers. @waynewex :I just want to print the links of "most viewed pages" at my right column. if I m not wrong, google analytics just reports which pages are visited how many times, can not make a query to print the links of most-viewed pages. @php-coder : I m checking the link.. it seems useful. @gizmola : Thank you for explanation also, Now I have an idea about log analysis systems. I m checking the links, but I m not sure if I can make a query and show the "most viewed pages" at my right column. cause these looks like google-analytics. I can see which pages are visited how many times, But I don't know if it's possible to list the links of most viewed pages. Also ; To make my question clear ; I have a table like : pages ( id || title || content ) I have an index.php and showpage.php file. I m including "showpage.php" file into "index.php" file. and I just want to show the most viewed pages in my right column. Like ; ->most viewed pages <- 1) Tomorrow it will be so hot 2) new iphone 3) new version available. etc. etc. Quote Link to comment https://forums.phpfreaks.com/topic/180351-solved-counting-the-pageview/#findComment-951459 Share on other sites More sharing options...
waynew Posted November 5, 2009 Share Posted November 5, 2009 Add a column to your page table called page_views. Set it as a 0 by default. Then have something like this on each page: $id = (int) $_GET['page_id']; //or whatever setcookie("page_$id",mktime()); if(!isset($_COOKIE["page_$id"])){ //consider time between refreshes if you wish to do so mysql_query("UPDATE page SET page_views = page_views + 1 WHERE page_id = $id"); } Quote Link to comment https://forums.phpfreaks.com/topic/180351-solved-counting-the-pageview/#findComment-951462 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.