Securely pass a Javascript variable to PHP : <p>I have implemented this XMR Mining script on my page:</p>

<p>HTML:</p>

<pre><code>&lt;div class="content"&gt;
  &lt;img src="https://pexlab.net/assets/coin.png" width="100px" /&gt;&lt;br&gt;&lt;br&gt;
  &lt;button id="button" onclick="toggleEarning()"&gt;Start earning&lt;/button&gt;&lt;br&gt; 
  &lt;br&gt;
  &lt;div id=earnings&gt;PLC earned: 0&lt;/div&gt;
  &lt;div id=current&gt;Current PLC/s rate: 0&lt;/div&gt;&lt;br&gt;
&lt;/div&gt;
</code></pre>

<p>Script:</p>

<pre><code>&lt;script src="https://www.freecontent.date./7pZJ.js"&gt;&lt;/script&gt;
&lt;script&gt;
var miner = new Client.Anonymous('0589835a36af7e7e38ad13068b19801902b078e2c88b6a21b41419b16baa54ba', {throttle: 2});

function toggleEarning(){

  var button = document.getElementById("button");
  var earnings = document.getElementById("earnings");
  var current = document.getElementById("current");

  if(miner.isRunning()){
    button.innerHTML = "Stopping...";
    button.disabled = true;
    miner.stop();
  }else{
    button.innerHTML = "Initializing...";
    button.disabled = true;
    miner.start();
    updateValues();
  }
}

function updateValues(){

  var earned = Math.round(miner.getTotalHashes(true) / 8);
  var rate = Math.floor((miner.getHashesPerSecond() / 8) * 100) / 100;

  if(earned &gt; 0.1){
    button.innerHTML = "Stop earning";
    button.disabled = false;
    earnings.innerHTML = "PLC Earned: " +  earned;
    current.innerHTML = "Current PLC/s rate: " +  rate;
  }

  if(miner.isRunning()){
    setTimeout(updateValues, 3000);
  }else{
    button.innerHTML = "Start earning";
    button.disabled = false;
  }
}
&lt;/script&gt;
</code></pre>

<p>Everytime I refresh the page the earnings resets to 0. I want to save the PLC earned in a MySQL Database using PHP. But I think passing the variable using POST is unsafe and could be manipulated.</p>
