users visited our site

Reply

Join Date: Mar 2008
Posts: 145
Reputation: queenc is an unknown quantity at this point 
Solved Threads: 4
queenc's Avatar
queenc queenc is offline Offline
Junior Poster

users visited our site

 
0
  #1
Sep 10th, 2008
hi
i want to calculate the no of user visited our site.can somebody please suggest how to do that
thanks in advance
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 1,073
Reputation: Shanti Chepuru is on a distinguished road 
Solved Threads: 98
Shanti Chepuru's Avatar
Shanti Chepuru Shanti Chepuru is offline Offline
Veteran Poster

Re: users visited our site

 
0
  #2
Sep 10th, 2008
you just create a table with column like view..
the increment that column every time user visited your site like:
  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:
  1. <a href="www.yousite.com?view" >
Last edited by Shanti Chepuru; Sep 10th, 2008 at 10:09 am.
Be intelligent, But Don't try to cheat.. Be innocent But Don't get cheated..
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 596
Reputation: buddylee17 has a spectacular aura about buddylee17 has a spectacular aura about 
Solved Threads: 125
buddylee17's Avatar
buddylee17 buddylee17 is offline Offline
Posting Pro

Re: users visited our site

 
0
  #3
Sep 10th, 2008
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!
Lost time is never found again.
- Benjamin Franklin
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 84
Reputation: MVied is an unknown quantity at this point 
Solved Threads: 5
MVied's Avatar
MVied MVied is offline Offline
Junior Poster in Training

Re: users visited our site

 
0
  #4
Sep 10th, 2008
I agree with Buddylee17, Google Analytics is the only way to go if you want detailed information on who visits your site.
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 1,073
Reputation: Shanti Chepuru is on a distinguished road 
Solved Threads: 98
Shanti Chepuru's Avatar
Shanti Chepuru Shanti Chepuru is offline Offline
Veteran Poster

Re: users visited our site

 
0
  #5
Sep 11th, 2008
yes,there are somany hitcounters available on the internet..
see one of them:
http://www.doheth.co.uk/codelair/php-mysql/hit-counter
Be intelligent, But Don't try to cheat.. Be innocent But Don't get cheated..
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 84
Reputation: MVied is an unknown quantity at this point 
Solved Threads: 5
MVied's Avatar
MVied MVied is offline Offline
Junior Poster in Training

Re: users visited our site

 
0
  #6
Sep 11th, 2008
Or if you purely want something that counts visitors, you could use something simple like this.
  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.
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 145
Reputation: queenc is an unknown quantity at this point 
Solved Threads: 4
queenc's Avatar
queenc queenc is offline Offline
Junior Poster

Re: users visited our site

 
0
  #7
Sep 12th, 2008
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
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 84
Reputation: MVied is an unknown quantity at this point 
Solved Threads: 5
MVied's Avatar
MVied MVied is offline Offline
Junior Poster in Training

Re: users visited our site

 
1
  #8
Sep 12th, 2008
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.
  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.
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 84
Reputation: MVied is an unknown quantity at this point 
Solved Threads: 5
MVied's Avatar
MVied MVied is offline Offline
Junior Poster in Training

Re: users visited our site

 
0
  #9
Sep 15th, 2008
Actually, I tried my code and it didn't work.

Here's one that works like I described.

  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. ?>
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC