P2P | IT Discussions Forum

Full Version: Simple visits counter!
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
1. Create a new folder named "counter"

2. Create a file named "counter.php"

3. Create a file named "counter.txt" - it will be used as a database.

4. Paste the following code into the "counter.php" file:

[code:1]<?
$fp = fopen("counter.txt", "r");
$visits = fread($fp, 1024) + 1;
$fp = fopen("counter.txt", "w");
fwrite($fp, $visits);
print "document.write('$visits');";
?>[/code:1]

5. Place this on your HTML pages where you want counter to be displayed:

[code:1]<script language="JavaScript" src="http://.../counter/counter.php"></script>[/code:1]

You should change "..." to the URL which is pointing to the "counter" folder.


Enjoy your simple visits counter.
Well thats a nice share and wonderful script. Just some queries. I used before some counters which counts every refresh of home page. Is that also like that... I need a counter which don't counts page views.... I mean it counts single IP visits as one in 24 hours. If you have or can code... Can u help me in that??
[code:1]<?
$fp = fopen("counter.txt", "r");
$visits = fread($fp, 1024) + 1;
[B]if($_COOKIE["visits_counter"]!=1){
[/B] $fp = fopen("counter.txt", "w");
[B]}[/B]
fwrite($fp, $visits);
[B]setcookie("visits_counter", "1", time()+86400);[/B]
print "document.write('$visits');";
?>[/code:1]

This way only one visit per 24h will be counted.
[code:1]<?
$fp = fopen("counter.txt", "r");
$visits = fread($fp, 1024) + 1;
[B]if($_COOKIE["visits_counter"]!=1){
setcookie("visits_counter", "1", time()+86400);
[/B] $fp = fopen("counter.txt", "w");
[B]}
[/B]
fwrite($fp, $visits);
print "document.write('$visits');";
?>[/code:1]

Sorry, this is the right code.
OK I will upload that today and check its working.... thanks NIKOLA.. You are really working hard
thank i'll try to my page if you don't mind can i take it to my friends
Sure Tphilakone,
you can use it anywhere you want.

It would be nice if you could put a link to this community on your website if you choose to use this script Smile
Nice tutorial..Just want to add that couter.txt must be 777 for linux based servers.or It won't work.
Reference URL's