Jump to content

Unique hit counter


Prodigal Son

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.