Run a script once yes and another not

0

I'm having a hard time creating logic and / or code.

I have a landing page that I need in a simple way, preferably without using a database, run a script once and sometimes not.

For example:

  • User 1 registers: executeScript ()
  • User 2 signs up: does not run script
  • User 3 subscribes: executaScript ()
  • User 4 signs up: does not run the script
  • User 5 subscribes: executaScript ()
  • User 6 signs up: does not run script
  • User 7 subscribes: executaScript ()
  • User 8 signs up: does not run the script

...

I even believe it can be done by using a simple database to control with true or false, but I'm running into logic for some time. Can anyone help?

It can be done in PHP or Vanilla JavaScript.

    
asked by anonymous 22.09.2017 / 15:42

3 answers

1

Users are registered where? They have some unique and sequential identification number, just do:

if($id_do_ususario % 2 === 0){
    executaScript();
}

This way when id is 1 it will not trigger, when it is 2 it will, when it is 3 it will not execute the command ... It will only execute the command in numbers divisible by 2.

    
22.09.2017 / 17:00
0

Hello, I do not understand much of PHP, but for what you want I think a simple solution + - like this:

$file = fopen("verifica.txt", 'r');
$ler = fgets($file, 1024);

if($ler > 0){
    fwrite($file, "1"); //Grava "1" no arquivo para saber que foi executada a função
    executaScript();
} else {
    fwrite($file, "0"); //Grava "0" no arquivo para saber que NÃO foi executada a função
}

fclose($file);
    
22.09.2017 / 15:58
0

Solution to the question:

$ler = file_get_contents("verifica.txt");

if($ler == "0"){
    file_put_contents("verifica.txt","1"); //Grava "1" no arquivo para saber que foi executada a função
    executaScript();
} else {
    file_put_contents("verifica.txt","0"); //Grava "0" no arquivo para saber que NÃO foi executada a função
}
    
22.09.2017 / 16:53