2

I run a podcast network and I'm redoing my site from scratch. One of the features on my network is to listen to podcasts directly from the site in an HTML5 player. I have all that functionality working just fine, but I'd like some analytical data on those pages.

I'd like to make a hit counter in PHP and store it in a DB table. But, there's only one page. The player loads each show, dependent on the query string, then it pulls the latest episode from their RSS Feed, like so: http://tangentboundnetwork.com/new/show.php?id=1

I want to be able to put analytical data into a table and use it for the hosts of whatever show(s) are on the network.

I just need to know where to start. Any ideas, Links, and examples would be welcome.

Mathew Tinsley
  • 6,805
  • 2
  • 27
  • 37
Mark Bogner
  • 451
  • 1
  • 5
  • 19
  • What is the `id` in the adress? Is it the ID of the show being listened to? If not, what is it? – Anders Jun 30 '15 at 15:06
  • 1
    How about this.. similar to what you need: http://www.devshed.com/c/a/PHP/Tracking-Website-Statistics-with-PHP/ – Jordan Jun 30 '15 at 18:57
  • @Anders - that is the id of the show. – Mark Bogner Jun 30 '15 at 20:47
  • @Jordan - I don't know if I need all that data, basically, I just need a quick hit counter. Though, that might be something I could use for the rest of the site - I'm kind of digging that. – Mark Bogner Jun 30 '15 at 20:48

1 Answers1

2

First, create your database table VISITOR_COUNT. You will need at least two columns - SHOW_ID and COUNT.

The code in show.php could look something like this:

  • If you want to count unique (or sort of unique - you can never be completely sure) visitors, check if a specific cookie for the current $id is set. Read more about cookies in PHP here.
  • If the cookie is not set:
    • Set the cookie.
    • Check if there is a row in VISITOR_COUNT with SHOW_ID = :id where :id is the value of $id. Watch out for SQL injection!
    • If there is, run some SQL to update it: UPDATE VISITOR_COUNT SET COUNT = COUNT + 1 WHERE SHOW_ID = :id
    • If not, insert a row with the right ID and a count value of 1.
Anders
  • 8,307
  • 9
  • 56
  • 88