943,907 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 1025
  • PHP RSS
Sep 10th, 2008
0

users visited our site

Expand Post »
hi
i want to calculate the no of user visited our site.can somebody please suggest how to do that
thanks in advance
Similar Threads
Reputation Points: 9
Solved Threads: 4
Junior Poster
queenc is offline Offline
145 posts
since Mar 2008
Sep 10th, 2008
0

Re: users visited our site

you just create a table with column like view..
the increment that column every time user visited your site like:
php Syntax (Toggle Plain Text)
  1. if(isset($_GET['view']))
  2. {
  3. $r="update viewtable set views=(views+1) ";
  4. $r1=mysql_query($r);
  5. }
  6. header("location:yournextpage.php");

and use this:
html Syntax (Toggle Plain Text)
  1. <a href="www.yousite.com?view" >
Last edited by Shanti C; Sep 10th, 2008 at 10:09 am.
Reputation Points: 137
Solved Threads: 162
Posting Virtuoso
Shanti C is offline Offline
1,641 posts
since Jul 2008
Sep 10th, 2008
0

Re: users visited our site

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!
Reputation Points: 232
Solved Threads: 137
Practically a Master Poster
buddylee17 is offline Offline
665 posts
since Nov 2007
Sep 10th, 2008
0

Re: users visited our site

I agree with Buddylee17, Google Analytics is the only way to go if you want detailed information on who visits your site.
Reputation Points: 21
Solved Threads: 11
Junior Poster
MVied is offline Offline
111 posts
since Aug 2008
Sep 11th, 2008
0

Re: users visited our site

yes,there are somany hitcounters available on the internet..
see one of them:
http://www.doheth.co.uk/codelair/php-mysql/hit-counter
Reputation Points: 137
Solved Threads: 162
Posting Virtuoso
Shanti C is offline Offline
1,641 posts
since Jul 2008
Sep 11th, 2008
0

Re: users visited our site

Or if you purely want something that counts visitors, you could use something simple like this.
php Syntax (Toggle Plain Text)
  1. <?php
  2. $counter_file = ("counter.txt");
  3. $visits = file($counter_file);
  4. $visits[0]++;
  5. $fp = fopen($counter_file , "w");
  6. fputs($fp , "$visits[0]");
  7. fclose($fp);
  8. echo "Hits: " . $visits[0];
  9. ?>

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.
Reputation Points: 21
Solved Threads: 11
Junior Poster
MVied is offline Offline
111 posts
since Aug 2008
Sep 12th, 2008
0

Re: users visited our site

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
Reputation Points: 9
Solved Threads: 4
Junior Poster
queenc is offline Offline
145 posts
since Mar 2008
Sep 12th, 2008
1

Re: users visited our site

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 Syntax (Toggle Plain Text)
  1. <?php
  2. $filename = 'hitcount.txt';
  3. $handle = fopen($filename, 'r');
  4.  
  5. if (!$_COOKIE['counter'] && $handle) {
  6. setcookie("counter", 1, time()+3600);
  7. $hits = trim(fgets($handle)) + 1;
  8. } else {
  9. $hits = trim(fgets($handle));
  10. }
  11.  
  12. fclose($handle);
  13. echo $hits;
  14. ?>

If you're using a different one, let me know and I can make similar changes to it.
Last edited by MVied; Sep 12th, 2008 at 4:10 pm.
Reputation Points: 21
Solved Threads: 11
Junior Poster
MVied is offline Offline
111 posts
since Aug 2008
Sep 15th, 2008
0

Re: users visited our site

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

Here's one that works like I described.

php Syntax (Toggle Plain Text)
  1. <?php
  2. $filename = 'hitcount.txt';
  3.  
  4. if (!$_COOKIE['counter']) {
  5. setcookie("counter", 1, time()+3600);
  6. $handle = fopen($filename, 'r');
  7. $hits = trim(fgets($handle)) + 1;
  8. $handle = fopen($filename, 'w');
  9. fwrite($handle, $hits);
  10. } else {
  11. $handle = fopen($filename, 'r');
  12. $hits = trim(fgets($handle));
  13. }
  14.  
  15. fclose($handle);
  16. echo $hits;
  17. ?>
Reputation Points: 21
Solved Threads: 11
Junior Poster
MVied is offline Offline
111 posts
since Aug 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: imap_fetchbody question
Next Thread in PHP Forum Timeline: Upload image folder





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC