Click counter

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
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
Unstoppable Domains — AI StorefrontUnstoppable Domains — AI Storefront
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
•••
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
•••
If anyone has a shorter way of doing this, please PM me.
 
0
•••
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
•••
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
•••
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
•••
so that would count the numer of clicks on your page?
 
0
•••
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
•••
lol. i would use global or shared, but....
 
0
•••
ahh e39, I'm lost.

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

I was off by 1 letter in the txt file name.
 
0
•••
wow. I hate it when i have mispelled a common word or something, and it looks right, lol.
 
0
•••
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
•••
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
•••
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
•••
Appraise.net

We're social

Escrow.com
Spaceship
Rexus Domain
CryptoExchange.com
Domain Recover
CatchDoms
DomDB
NameFit
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back