Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder Andy92's Avatar
    Join Date
    Nov 2005
    Location
    Horsham, West Sussex, UK
    Posts
    363
    Thanks
    7
    Thanked 1 Time in 1 Post

    Page views with php

    Hi there,

    Basically on my blog, i want it to say at the bottom of each post how many page views it has.

    How can i do this?

  • #2
    Senior Coder whizard's Avatar
    Join Date
    Jan 2005
    Location
    Philadelphia, PA, USA
    Posts
    1,662
    Thanks
    14
    Thanked 76 Times in 76 Posts
    Have each page add 1 to a counter for that page in the database when it is loaded

    Dan
    PHP Tip: If you want to use short tags (<? or <?=$var) then make sure short_open_tag is set to "1". It really helps.

    Don't forget to save everyone time and mark your thread as Resolved :)

    "Also note that it is your responsibility to die() if necessary."

    DON'T USE THE MYSQL_ EXTENSION

  • #3
    Regular Coder Andy92's Avatar
    Join Date
    Nov 2005
    Location
    Horsham, West Sussex, UK
    Posts
    363
    Thanks
    7
    Thanked 1 Time in 1 Post
    Yes, thats a good idea, but people could just keep refreshing the page and it would add 1 to the counter for that page.

    How can i prevent this?

  • #4
    Senior Coder whizard's Avatar
    Join Date
    Jan 2005
    Location
    Philadelphia, PA, USA
    Posts
    1,662
    Thanks
    14
    Thanked 76 Times in 76 Posts
    Well.. maybe if there is a new IP address add one to the database? Or use session variables to determine which pages have been viewed already?

    Beyond that, it seems to me that even if its just a refresh, it is a page view, so if that is what you are trying to count, thats what will be counted.

    HTH
    Dan
    PHP Tip: If you want to use short tags (<? or <?=$var) then make sure short_open_tag is set to "1". It really helps.

    Don't forget to save everyone time and mark your thread as Resolved :)

    "Also note that it is your responsibility to die() if necessary."

    DON'T USE THE MYSQL_ EXTENSION

  • #5
    Regular Coder Andy92's Avatar
    Join Date
    Nov 2005
    Location
    Horsham, West Sussex, UK
    Posts
    363
    Thanks
    7
    Thanked 1 Time in 1 Post
    Ok,

    An example i have sene is at...

    http://www.johnchow.com/yangmingshan...-in-the-world/

    Have a look just before the comments at the bottom of the post. It says...

    Posted in Ramblings | | 3,840 Views | Random Post

    How do you think that they count their views on the john chow blog?

    Do you think that they log each persons ip address for 1 hour, so that if they keep refreshing the page it wont count the page view, and then after the hour if they refresh the page it will add another page view.

    So basically, each person is only allowed to have 1 page view per hour on the same page.



  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •