Jump to content

[SOLVED] Counting the pageview?


Rommeo

Recommended Posts

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.

Link to comment
Share on other sites

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

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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. 

 

 

Link to comment
Share on other sites

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 ?

 

Link to comment
Share on other sites

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.

 

 

 

 

 

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

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");
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.