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