Jump to content

[SOLVED] Hit Counter?


divadiva

Recommended Posts

I have a webpage and I want to know how many different people are visiting my webpage.Is there a way to do that.

 

I have use hit counter.It tells me the total number of hits.I want to track different IP addresses/people.Is there a way to do it.

 

Thankyou in advance.

 

Best Regards

Gagan

Link to comment
https://forums.phpfreaks.com/topic/122879-solved-hit-counter/
Share on other sites

Very easy with a database.

 

ON every page, execute a query like this

 

INSERT INTO `counter` (`ip`) VALUES ( '{$_SERVER['REMOTE_ADDR']}')

 

Then to view hits, simply use

 

SELECT COUNT(*) as `total`, COUNT(DISTINCT `ip`) as `unique` FROM `counter`

Link to comment
https://forums.phpfreaks.com/topic/122879-solved-hit-counter/#findComment-634628
Share on other sites

Thanks for replying!!

 

I am trying this codewhich I have taken from web

 

<?
$db = mysql_connect("172.16.24.3", "gvirk", "G@g@n1");
	mysql_select_db("test",$db);

			mysql_query("UPDATE user_hits SET counter=counter+1
  				WHERE page = '$PHP_SELF' AND ip='$ip' AND ref='$HTTP_REFERER' ",$db);

  				if (mysql_affected_rows($db) < 1) {
    				$result = mysql_query("INSERT INTO user_hits VALUES ('$PHP_SELF', '$ip', '$HTTP_REFERER', 1)", $db);
    							} 

	mysql_close($db); 
?>

 

 

But I get an error that httpreferer,phpself is not defined.Can anyone guide me through this?

 

Thankyou in advance

 

 

Best Regards

Divya

Link to comment
https://forums.phpfreaks.com/topic/122879-solved-hit-counter/#findComment-634643
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.