Categories > Coding > PHP >
Download / hit counter
Posted
This is a very basic download counter, can be used for page visits, download detecting or more
visit Count Tutorial:
<?php
$count = @file_get_contents('count.txt'); // reads the download count from the file
$count++; // adds 1 to the count
echo $count; // displays the count
@file_put_contents('count.txt', $count) // saves the updated count
?>
Download Count Tutorial:
Create a php file named something like "download-file.php" and put this code within
<?php
$count = @file_get_contents('count.txt');
$count++;
@file_put_contents('count.txt', $count);
header('Location: http://example.com/download/file.zip'); // redirects to download the file
?>
Make a button and instead of linking to the file, link to the PHP file you just created
http://example.com/download-file.php
To display the download count, use this code (styling etc should be done in css)
<p><?php include 'count.txt'; ?></p> // "include" is a quick way to read a file/add external pages to the current page
Hope this tutorial helps! Any questions can be posted below!
Replied
next tutorial: how to be a html coder in 10 minutes
Cancel
Post
Added
@53326ew
Cancel
Post
yes
Replied
Cool tutorial bro :D
Cancel
Post
Replied
ok..
Cancel
Post
Replied
This is really neat
Cancel
Post
Proud owner of Artemis
I quit exploiting
I might buy Premium soon!
Users viewing this thread:
( Members: 0, Guests: 1, Total: 1 )
Cancel
Post