Here i have found a JavaScript button click counter that counts the no. of clicks on a button and saves the number in something called web storage, I don't know what that really is.
One thing I know for sure that this script only works for one computer, meaning if I click the button 10 times then if any other visitor clicks the button it will not show that number of clicks to him which i have clicked before.
Now what i need is that, somehow either with javascript or php, the number of clicks should be saved on a text file in my server, and later whenever any other visitor visits the HTML page he also should get the same number which is present in the text file.
Here the HTML
Page with the code.
<!DOCTYPE html>
<html>
<head>
<script>
function clickCounter()
{
if(typeof(Storage)!=="undefined")
{
if (localStorage.clickcount)
{
localStorage.clickcount=Number(localStorage.clickcount)+1;
}
else
{
localStorage.clickcount=1;
}
document.getElementById("result").innerHTML="You have clicked the button " + localStorage.clickcount + " time(s).";
}
else
{
document.getElementById("result").innerHTML="Sorry, your browser does not support web storage...";
}
}
</script>
</head>
<body>
<p><button onclick="clickCounter()" type="button">Click me!</button></p>
<div id="result"></div>
<p>Click the button to see the counter increase.</p>
<p>Close the browser tab (or window), and try again, and the counter will continue to count (is not reset).</p>
</body>
</html>
In a simple way,
There is a button on an HTML page.
If visitor A clicks it for 5 times and close the page.
And later, visitor B visits the page he should get the number 5 first, and then when he clicks, it should get counted and saved automatically.
ajax call
to send the datato the server
. The server then needs to evaluate the response, and open the file, write into the file, then close the file. Now, everytime thepage is requested
you'll need to include the text in that file, and use the text as a counter.