Jump to content

Hit counter for each page


sharpcode

Recommended Posts

I have a video section and what i want is to eventually add a sort by popular button so i am trying to track the views on each video. So i have videos.php which is the gallery page then video.php that has the content shown on it. What i need is for the 'views' column to be incremented for each 'videocode' that gets viewed.

 

  $video = $_REQUEST['code'];

  error_reporting(E_ALL); 

  $con = mysql_connect("localhost","user","password") or die("Cannot connect");

  mysql_select_db("my_db") or die(mysql_error());

  $query = "SELECT * FROM videos WHERE code='$video' LIMIT 1";

  $result = mysql_query($query,$con) or die("Result Query Error");

  $row = mysql_fetch_array($result);

  // print out video and content here

 

So i figure i need to use $video somehow i am a bit lost with how to get started. Because at the same time i need to use sessions possibly so it doesn't count spam clicks and so on. Any hints or links that can push me in the right direction i would be very happy :)

Link to comment
Share on other sites

Rather than just incrementing a counter, you need to use a database table to store all the relevant information, one row per view. You would store the datetime, user_id, video_id, ip address, session_id, and the user-agent of the browser.

 

Once you have this information stored, you can use it to filter out things like duplicate views by the same user and produce reports on usage.

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.