Categories > Coding > PHP >

Download / hit counter

Posts: 161

Threads: 31

Joined: Sep, 2019

Reputation: 19

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!

  • 0

 

 

jex

yes

Posts: 1985

Threads: 128

Joined: Nov, 2019

Reputation: 13

Replied

next tutorial: how to be a html coder in 10 minutes

  • 0

Added

@53326ew                        

  • 0

yes

Posts: 421

Threads: 28

Joined: Jan, 2018

Reputation: 14

Replied

Cool tutorial bro :D

  • 0

Posts: 23

Threads: 2

Joined: Apr, 2020

Reputation: -20

Replied

ok..                     

  • 0

TeekTacker

(apparently) YNW Melly

Posts: 921

Threads: 111

Joined: Jan, 2019

Reputation: -95

Replied

This is really neat

  • 0

Proud owner of Artemis

I quit exploiting

I might buy Premium soon!

Users viewing this thread:

( Members: 0, Guests: 1, Total: 1 )