HTML download counter without PHP

yotube
0

Issue

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.


Solution

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>





Answered By - zeachco

Post a Comment

0Comments
Post a Comment (0)

#buttons=(Accept !) #days=(20)

Our website uses cookies to enhance your experience. Learn More
Accept !
To Top