954,561 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

users visited our site

hi
i want to calculate the no of user visited our site.can somebody please suggest how to do that
thanks in advance

queenc
Junior Poster
145 posts since Mar 2008
Reputation Points: 9
Solved Threads: 4
 

you just create a table with column like view..
the increment that column every time user visited your site like:

if(isset($_GET['view']))
{
 $r="update viewtable  set views=(views+1)  ";
$r1=mysql_query($r);
}
 header("location:yournextpage.php");


and use this:

<a href="www.yousite.com?view" >
Shanti C
Posting Virtuoso
1,642 posts since Jul 2008
Reputation Points: 137
Solved Threads: 162
 

You could also use Google Analytics . It will give you a hit count, average time on site, keywords used to find the site, traffic sources (referring site), breakdown of stats of which search engine was used to find your site, pages per visit, a global map view of where the hits came from, individual page stats, and more!

buddylee17
Practically a Master Poster
697 posts since Nov 2007
Reputation Points: 232
Solved Threads: 137
 

I agree with Buddylee17, Google Analytics is the only way to go if you want detailed information on who visits your site.

MVied
Junior Poster
112 posts since Aug 2008
Reputation Points: 21
Solved Threads: 11
 

yes,there are somany hitcounters available on the internet..
see one of them:
http://www.doheth.co.uk/codelair/php-mysql/hit-counter

Shanti C
Posting Virtuoso
1,642 posts since Jul 2008
Reputation Points: 137
Solved Threads: 162
 

Or if you purely want something that counts visitors, you could use something simple like this.

<?php
 $counter_file = ("counter.txt");
 $visits = file($counter_file);
 $visits[0]++;
 $fp = fopen($counter_file , "w");
 fputs($fp , "$visits[0]");
 fclose($fp);
 echo "Hits: " . $visits[0];
?>


Then just make a blank text file named "counter.txt" in the same directory as the file that contains this snippet. You could even go as far as to create a cookie to make sure you don't get duplicate entries from the same visitor. I know this isn't great, but it's just a thought.

MVied
Junior Poster
112 posts since Aug 2008
Reputation Points: 21
Solved Threads: 11
 

hi i tried shanthi's counting....it works fine but each time when i refresh the count is getting incremented.....i want a browser to be counted as 1 ie when user closes the browser then it can counted but counting every time when refresh button is clicked is not wat i desired...plaese tell me how to do tat

queenc
Junior Poster
145 posts since Mar 2008
Reputation Points: 9
Solved Threads: 4
 

I've taken code from Shanthi's post and edited to to set a cookie when a user visits the page. When the user refreshes the page, it checks for the cookie. If the cookie exists, it does not add to the counter, and if it doesn't, it does add to the counter. Afterward, it prints the hits.

<?php
$filename = 'hitcount.txt';
$handle = fopen($filename, 'r');

if (!$_COOKIE['counter'] && $handle) {
 setcookie("counter", 1, time()+3600);
 $hits = trim(fgets($handle)) + 1;
} else {
 $hits = trim(fgets($handle));
}

fclose($handle);
echo $hits;
?>


If you're using a different one, let me know and I can make similar changes to it.

MVied
Junior Poster
112 posts since Aug 2008
Reputation Points: 21
Solved Threads: 11
 

Actually, I tried my code and it didn't work. :P

Here's one that works like I described.

<?php
$filename = 'hitcount.txt';

if (!$_COOKIE['counter']) {
 setcookie("counter", 1, time()+3600);
 $handle = fopen($filename, 'r');
 $hits = trim(fgets($handle)) + 1;
 $handle = fopen($filename, 'w');
 fwrite($handle, $hits);
} else {
 $handle = fopen($filename, 'r');
 $hits = trim(fgets($handle));
}

fclose($handle);
echo $hits;
?>
MVied
Junior Poster
112 posts since Aug 2008
Reputation Points: 21
Solved Threads: 11
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You