| | |
users visited our site
![]() |
you just create a table with column like view..
the increment that column every time user visited your site like:
and use this:
the increment that column every time user visited your site like:
php Syntax (Toggle Plain Text)
if(isset($_GET['view'])) { $r="update viewtable set views=(views+1) "; $r1=mysql_query($r); } header("location:yournextpage.php");
and use this:
html Syntax (Toggle Plain Text)
<a href="www.yousite.com?view" >
Last edited by Shanti Chepuru; Sep 10th, 2008 at 9:09 am.
Be intelligent, But Don't try to cheat.. Be innocent But Don't get cheated..
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
- Benjamin Franklin
yes,there are somany hitcounters available on the internet..
see one of them:
http://www.doheth.co.uk/codelair/php-mysql/hit-counter
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..
Or if you purely want something that counts visitors, you could use something simple like this.
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.
php Syntax (Toggle Plain Text)
<?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.
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
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.
If you're using a different one, let me know and I can make similar changes to it.
php Syntax (Toggle Plain Text)
<?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.
Last edited by MVied; Sep 12th, 2008 at 3:10 pm.
Actually, I tried my code and it didn't work. 
Here's one that works like I described.

Here's one that works like I described.
php Syntax (Toggle Plain Text)
<?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; ?>
![]() |
Similar Threads
- count no of Visitors (ASP.NET)
- Check out this site and Rate it (Website Reviews)
- Please Review My Site (Website Reviews)
- Would like advice on new site (Website Reviews)
- Advertise on well visited game site (text links and banner) (Ad Space for Sale)
- Finally an alternative to the google toolbar for mac users! (Search Engine Optimization)
Other Threads in the PHP Forum
- Previous Thread: imap_fetchbody question
- Next Thread: how to detect online visitors and members??
Views: 926 | Replies: 8
| Thread Tools | Search this Thread |
Tag cloud for PHP
.htaccess access ajax apache api archive array arrays auto binary box buttons cakephp check checkbox class cms code css curl database date directory display download dropdown dynamic echo email error file files form forms function functions header href htaccess html image include insert integration ip java javascript joomla jquery limit link list login lookup loop mail menu methods mlm mod_rewrite multiple mysql order output parse paypal php problem query radio random redirect regex remote rewrite script search select server session shopping sort source speed sql string table update upload url user validate validation variable video web website wordpress xml zend






