c-o-d-e Posted December 10, 2009 Share Posted December 10, 2009 I have a hit counter, for the amount of views on a tutorial. It'll do the query and then do.. $views = $row['views'] + 1; Then insert $views into the database. This updates the view for each refresh of the page, and more than once per IP. I am confused as to how I'll check for IP. When a tutorial is posted, it has the IP of the person who posted it aswell as their username. If I checked if the IP isn't in the database on that tutorial, to ip view status. That means that the person who posted the tutorial couldn't update the view on there.. visit to there tutorial. Though other visitors could update the view status on each refresh. I am not sure how to do it. The database table has these fields: Username Tutname Tutorial TimePosted IP Views Any idea how I'd do it so that "Views" updates by +1 ONCE per visit by IP. Link to comment https://forums.phpfreaks.com/topic/184639-hit-counter-updating-once-per-ip-ip-hit-counter/ Share on other sites More sharing options...
Buddski Posted December 10, 2009 Share Posted December 10, 2009 My best guess, if I understand the question correctly would be, you need to store the visitors IP address along with the tutorial id (or whatever is unique) then when a visitor views the tutorial again, you will need to look up their IP address in the new table for that tutorial and if it doesnt exist.. add it then increase the view count by 1.. eg. - User visits tutorial #1 with the IP 127.0.0.1 - run a query on the IP storage table (eg SELECT * FROM `ip_storage` WHERE `ip`='127.0.0.1' AND `tutorial`='tutorial #1' - if there is a result take no action. - if there is no results, add 127.0.0.1 and tutorial #1 to the ip_storage table and increase the tutorial #1 view by 1. There may be a better solution but thats my 2 cents. Link to comment https://forums.phpfreaks.com/topic/184639-hit-counter-updating-once-per-ip-ip-hit-counter/#findComment-974828 Share on other sites More sharing options...
c-o-d-e Posted December 10, 2009 Author Share Posted December 10, 2009 I understand what your saying. How will the table look like... because it'd be called Views for example.. but I'm not sure? It'd end up with a veryy long table. Unless the IP section ended up like.. IP 127.0.0.1, 144.13.423, 234.123.43 And so on.. so it'd end up with a long string.. possibly? but I'm not sure how I'd enter it like that. Also how I'd check it, because it'd check for the whole string wouldn't it? Link to comment https://forums.phpfreaks.com/topic/184639-hit-counter-updating-once-per-ip-ip-hit-counter/#findComment-974911 Share on other sites More sharing options...
Buddski Posted December 10, 2009 Share Posted December 10, 2009 Ok lets say you have your tutorial table with these fields: Tut_ID (unique) Username Tutname Tutorial TimePosted Views and a second table with these fields Tut_ID IP A user creates a tutorial which will insert the tutorial into the first table and then insert his IP address with the associated Tut_ID into the second table.. When a user comes along and views the tutorial, you script could check the second table for that IP address. So basically you second table will be filled with IP addresses like so: Tut_ID IP 1 127.0.0.1 2 127.0.0.1 1 192.168.0.1 3 192.168.0.4 This would mean that the person with IP address 127.0.0.1 has viewed Tut_ID 1 and Tut_ID 2 but they havent viewed Tut_ID 3 yet.. so when they finally view it.. that tutorials count will go up by one and the second table will be as follows: Tut_ID IP 1 127.0.0.1 2 127.0.0.1 1 192.168.0.1 3 192.168.0.4 3 127.0.0.1 Link to comment https://forums.phpfreaks.com/topic/184639-hit-counter-updating-once-per-ip-ip-hit-counter/#findComment-974921 Share on other sites More sharing options...
c-o-d-e Posted December 11, 2009 Author Share Posted December 11, 2009 I understand. Does anyone else have any ways of this? Would this be the best? Link to comment https://forums.phpfreaks.com/topic/184639-hit-counter-updating-once-per-ip-ip-hit-counter/#findComment-975134 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.