Prodigal Son Posted September 18, 2008 Share Posted September 18, 2008 I'm making some dynamic web pages and each of them has a hit counter, but it's not unique. I just have the value stored in the db. And each time someone accesses the page, I do an update to the db and increment it by one. Some people use cookies for a unique hit counter right? But if you have many dynamic pages, would you really make a cookie for each page? What's the best way to make a unique hit counter for dynamic pages? Link to comment https://forums.phpfreaks.com/topic/124842-unique-hit-counter/ Share on other sites More sharing options...
F1Fan Posted September 18, 2008 Share Posted September 18, 2008 I created one that has a db table with one column that stores the feature accessed (the page) and another that has the count. <?php $query = "UPDATE feature_count SET c = (c+1) WHERE f = '$f'"; $result = $db->query($query); if ($db->affectedRows()==0){ $query = "INSERT INTO feature_count (f, c) VALUES ('$f', 1)"; $result = $db->query($query); } ?> Link to comment https://forums.phpfreaks.com/topic/124842-unique-hit-counter/#findComment-644928 Share on other sites More sharing options...
dennismonsewicz Posted September 18, 2008 Share Posted September 18, 2008 Well the problem with "unique hit counters" is that they are never a true unique counter. You seem to be on your way by calculating the information using a DB but you may have to get into capturing IP addresses as well... Link to comment https://forums.phpfreaks.com/topic/124842-unique-hit-counter/#findComment-644929 Share on other sites More sharing options...
Prodigal Son Posted September 18, 2008 Author Share Posted September 18, 2008 So its not a good idea to use cookies? (I also remember reading that there is only 20 cookies per domain??) How about sessions? Link to comment https://forums.phpfreaks.com/topic/124842-unique-hit-counter/#findComment-645052 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.