sharpcode Posted January 9, 2013 Share Posted January 9, 2013 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 Quote Link to comment https://forums.phpfreaks.com/topic/272892-hit-counter-for-each-page/ Share on other sites More sharing options...
PFMaBiSmAd Posted January 9, 2013 Share Posted January 9, 2013 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. Quote Link to comment https://forums.phpfreaks.com/topic/272892-hit-counter-for-each-page/#findComment-1404429 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.