1

I'm wondering if it's possible to make a download counter without the use of php. I have been told it's possible but cannot find anywhere that has helped me.

I am trying to save the counts to text file on the server. I cannot use php as my server does not allow the use of it. I have tried javascript but can't seem to get anything working. Any suggestions or guidance would be appreciated!

The server allows, html, javascript, and css.

John Kens
  • 1,615
  • 2
  • 10
  • 28

2 Answers2

1

PHP is the most common server language available on hosting services, if your server does not allow it, it's possible you can't use any language at all on the server side.

Let's assume you can't use any language on the server side, then there is two possible actions.

  1. use a third party server where you can save your data.
  2. save locally your data using javascript.

Using a 3rd party service might be complex to implement and you need to learn a bit about cross origin request. You will need to add a few javascript librairies and understand a lots of concept so I'll just go with the easy one.

You browser have a localStorage wich can be access through Javascrip https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage

[!] Know that this will be save only on your browser therefore other users or session will not have access to the counter.

// get the saved value or zero if not found
var count = localStorage.getItem('so-demo') || 0;

// increment the value by 1
count++;

// save the value
localStorage.setItem('so-demo', count);

// show the actual value
document.getElementById('theValue').innerHTML = count
<div id="theValue">localStorage is not allowed on stack overflow but works elsewhere</div>
zeachco
  • 754
  • 4
  • 16
0

The similar question had already been raised, check out this topic

The way suggested with Google Analytics out there is quite a good idea

Senpai.D
  • 439
  • 3
  • 14
  • I believe that does not display the current downloads. – John Kens Oct 27 '17 at 22:18
  • @JohnKens, sir you may believe in aliens or unicorns, but there are some certain reasons to believe in GA if your server has only js+html. The only thing I sure know is that you can track clicks on your file download link in the environment you've described. – Senpai.D Oct 27 '17 at 22:34