mercredi 4 mai 2016

Advice on: php lottery system [on hold]

I was wondering if i could get some advice on how to handle the following:

Say an user leaves her/his email address when he does she/he has 1/3 chance of winning (she/he'll get a notice directly). There are 100 prices to give away after that the chance of winning is 0. This is what i've taught out so far (really simple example). Basically you need to keep track of the winners and store this with (encryption?) in a database (data.txt in this example).

Anyone else got some advice on doing this? or has done something similar?

 $file = 'data.txt'; // number 1-99
    if(file_get_contents($file) < 99) {
        if(rand(1,3) == 2) {
            echo 'We got a winner';
            $current = file_get_contents($file);
            $current++;
            file_put_contents($file, $current);
        } else {
          echo 'We got a loser'
        }
    } else {
      echo 'We got a loser'
    }




Aucun commentaire:

Enregistrer un commentaire