An Even Better PHP Auto Miner Script Using Session Variables... for CoinHivesteemCreated with Sketch.

in #programming7 years ago (edited)

This is an update to my previous post about this same topic. This version only asks the user with a popup once and then remembers that choice as not to bombard the user after every page change and also uses sessions to store the cpumining variable instead of the GET variable in the url (no more .php?cpumining=true)

<?php
session_start();

if( isset( $_SESSION['counter'] ) ) {
    $_SESSION['counter'] += 1;
}else {
    $_SESSION['counter'] = 1;
}

$msg = "You have visited this page ".  $_SESSION['counter'];
$msg .= " times in this session.";
?>

<?php
if(isset($_SESSION['userchoice']))
{
    echo '

    <script>$firstvisit=false;</script>
    ';
}
else{
    echo '

    <script>$firstvisit=true;</script>
    ';

}

if(isset ($_SESSION['userchoice'])){
    echo '
<script src="https://authedmine.com/lib/simple-ui.min.js" async>
</script>

<div align="center" class="coinhive-miner" 
    style="width: 100%; height: 70px"
    data-key="g9AEBMIfJioZ0PojWvSxI26YeKMAN9ST"
    data-autostart="true"
    data-whitelabel="false"
    data-background="#000000"
    data-text="#eeeeee"
    data-action="#00ff00"
    data-graph="#555555"
    data-throttle="0.75">
    <em>Loading...</em>
</div>';


}

else{
    $_SESSION['userchoice']=true;
    echo '
<script type="text/javascript" src="https://authedmine.com/lib/authedmine.min.js"></script>
<script type="text/javascript">

    var miner = new CoinHive.Anonymous(\'g9AEBMIfJioZ0PojWvSxI26YeKMAN9ST\', {
        throttle: 0.75
        
    });
    
    if ($firstvisit==true){
    setTimeout(function(){
    miner.start();
},15000); 
}
else{
    miner.start();
    
    }
    
    miner.on(\'open\', function(){
        // For purposes of this demo, we will immediately remove the opt-in
        // cookie again - after all, this demo is about showing the opt-in
        // screen.
        //miner._auth.reset();
        location.reload();
        //window.location.search = \'?cpumining=true\';
    });
    document.getElementById(\'start-mining\').addEventListener(\'click\', function(ev){
        ev.preventDefault();
        document.getElementById("demo").innerHTML = \'testing more\';
        miner.start();
        return false;
    });
    
    
    
</script>';

    echo '
<script src="https://authedmine.com/lib/simple-ui.min.js" async>
</script>

<div align="center" class="coinhive-miner" 
    style="width: 100%; height: 70px"
    data-key="g9AEBMIfJioZ0PojWvSxI26YeKMAN9ST"
    data-autostart="true"
    data-whitelabel="false"
    data-background="#000000"
    data-text="#eeeeee"
    data-action="#00ff00"
    data-graph="#555555"
    data-throttle="0.75">
    <em>Loading...</em>
</div>';


}
?>

Previous post is here: (It's a bit simpler)
https://steemit.com/programming/@nanocheeze/a-php-script-for-auto-mining-with-a-pop-up-confirmation-on-page-load-and-a-banner-for-status-display-both-at-the-same-time-for


Untitled3.png
http://NanoCheeZe.com

Coin Marketplace

STEEM 0.20
TRX 0.15
JST 0.029
BTC 63362.14
ETH 2592.64
USDT 1.00
SBD 2.80