Dynadot .com transfer sale, only $10.12 with coupon code DYNA12, available while supplies last, ends October 31, 2026.

Click counter

Namecheap AuctionsNamecheap Auctions
Namecheap AuctionsNamecheap Auctions
SpaceshipSpaceship
Watch

BoRiCuA

Established Member
Impact
0
counter.php -

<?php
if($count=="NAME-OF-SITE") {

$file = "NAME-OF-SITE.txt";
$open = fopen($file, "r");
$size = filesize($file);
$count = fread($open, $size);
fclose($open);

$open = fopen($file, "w");
$count++;
fwrite($open, $count);
fclose($open);

Header('Location: http://URL-OF-SITE');
exit;
}
?>



For the link:

<a href="http://www.YOURSITE.com/counter.php?count=NAME-OF-SITE">NAME-OF-SITE</a>


For the counter:

<?PHP
include("NAME-OF-SITE.txt");
?>

----

Make a .txt file and put "0" w/o the " but name it the name of the site. CHMOD this file to 777.

All the "NAME-OF-SITE"'s must math.
 
Last edited:
0
Close
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
quick question, the top code I guess is the PHP file and the link, where does the counter code go is it also inside the php file?

Sorry if I sound dumb, quite new to PHP
 
0
Close
You have to make a new document called counter.php and paste the first code into the document.

To display the link, you MUST make the page .php and paste the link code.

To display the counter, you MUST make the page .php and paste the counter code.


<?php
if($count=="NAME-OF-SITE") {

^^See NAME-OF-SITE ? That has to match this part:
counter.php?count=NAME-OF-SITE

$file = "NAME-OF-SITE.txt";

^^See this part? That has to match:
<?PHP
include("NAME-OF-SITE.txt");



If you have any questions, just e-mail me
 
0
Close
If anyone has a shorter way of doing this, please PM me.
 
0
Close
you wont find a shorter way of doing it, it is only 13 lines of code,

1 note however you would need to chmod the txt file otherwise php will not be able to write to the file.
 
0
Close
There is another way of writing it because everytime I want to make another counter, I have to make another php file. I have seen people use only 1 php file for all their counters.

Yes filth, I forgot to include that. Thnx for telling me.
 
0
Close
just add variables into the link instead of in counter.php, i don't have time to code it here right now but you should be able to figure it out if you coded that
 
0
Close
so that would count the numer of clicks on your page?
 
0
Close
n the link you would also have the vars for the txt filename and the header location, those are the only two vars that aren't common in the counter.php file, with the uncommon vars out, counter.php is a common file and can be used by multiple links, i hope common was the right word there
 
0
Close
lol. i would use global or shared, but....
 
0
Close
ahh e39, I'm lost.

I'll give it another try. Last time it gave me a migraine!
 
0
Close
lol
 
0
Close
i always see this thread when i don't have time, lol, idevise, you think you can code it out?
 
0
Close
say what? lol, if i read and learn more ya.
 
0
Close
Ahhh no wonder!

I was off by 1 letter in the txt file name.
 
0
Close
wow. I hate it when i have mispelled a common word or something, and it looks right, lol.
 
0
Close
I wrote a site - www.CodeStats.com - that does something similar, but adds a counter... your code is useful though ;) Maybe you should write an auto-installer for download?
 
0
Close
compuXP said:
I wrote a site - www.CodeStats.com - that does something similar, but adds a counter... your code is useful though ;) Maybe you should write an auto-installer for download?
Check the date, more than a year old. ;) No use in bringing up old, old, threads.
 
0
Close
Hmph. Suppose somebody found it useful... and wanted to comment on it... just... HYPOTHETICALLY.

Cause I didn't know how to read a single number from a file then update it... file system is NOT my thing in PHP, so I'm just complementing the author.
 
0
Close
AIVikingsAIVikings

We're social

Escrow.com
Spaceship
CryptoExchange.com
Domain Recover

NamePros updates

Quick replies: search, your most used replies, and more on every post
Quick replies are easier to find and use now. The quick reply menu has a search box. Type a few letters to find the reply you want. A...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back