How to delete the database from the database if the user does not activate it by email within "X" hours?

5

Well, when registering on the site the user has their ACTIVE set to 0, so with the code I posted in the question answer below I can update the ACTIVE to 1: How do I activate a user's registration by email?

But if the user does not activate the data they will continue to occupy space in my database. Then someone can just fill up my bank of emails.

How to delete this data if the registration is not activated in a certain time?

    
asked by anonymous 21.08.2014 / 17:06

4 answers

3

Guys I'm not a programmer, I'm in the group as an enthusiast . I ask questions to find out what I do not know and to gain insights.

I was able to resolve the situation this way:

First I did this:

At the time of registration I sent the time (); to the data_ts field of my table.

So when the user tries to log in the code below, he checks if the asset is 0 or 1. If it is 0 and it still has not been 24h after the registration time, I ask that he access the email to activate, then I delete that table from the table:

         if ($ativo != 1)
         {      
          $tempo_agora = time();

          if (($tempo_agora - $tempo_cadastro) >= 86400)
          {
          $excluir_cadastro = DBDrop('tabela', "email = '$email'"); 
          //DBDrop é minha função para fazer exclusões

          $erros = "Seu cadastro expirou! Após se alistar você tem até 24h 
                    para acessar seu e-mail e ativar sua conta!
                    Agradecemos a compreensão!";
          }
      else {        
             $erros = "Acesse seu e-mail para validar seu cadastro!";}
    } 

But then I realized that I did not resolve the situation because the user could simply never try to log in, so the data would remain in the database. So I made this function (in a separate file) to put on the home page through a require:

<?php
//Exclui linhas não ativadas em até 24h
function vinte_e_quatro () {

 $tempo_agora = time();

 $query = DBDrop('tabela', "ativo='0' AND (data_ts + 86400) <= '$tempo_agora' "); 

}
?>

Very pleased with the result, thank you all for guiding me!

    
21.08.2014 / 20:52
9

You can create a script that will be run by the server at any given time to remove users with ativo=0 from the table if the expiration time has already been reached. Or maybe a parallel application to do this.

If you choose the first option, you can use the cron - of Linux - or the Task Scheduler - of Windows - to run the verification script.

    
21.08.2014 / 17:15
7

Just use a query immediately before the verifier that simply delete all records that have passed a certain time, and whose asset is zero.

If you query this in a separate PHP file, you can use several techniques simultaneously:

  • Call this PHP with require_once some line (s) before doing the activation. This can be done independently and concomitantly to the following two techniques, and is used for the registration to be eliminated even if the scheduled task did not run right at that moment;

  • "run" this PHP via cron / scheduler as already mentioned in another answer;

  • And if you do not have access to cron or other form of scheduling, put a counter that runs this PHP with include in another PHP that is customarily accessed on the site. For example, with every n access, PHP includes the query script. (you can do all the access as well, but for performance reasons you usually do not need to run at all times).

21.08.2014 / 20:05
2

Very simple, you will have to create an automation script that will be included in a main page of your site, every time someone logs in, it will execute this script.

Look, you'll have to make a field in the user's table named "last entry", and every time the user is logged in, there will be a script that will update this table with% / p>

You create a script, which will be included in the main pages of the site's client area, that is, every time you refresh the page, your last entry will be updated to the time you updated the page, right?

Now you just have to create a script that prints all the entries and compare the last update with the current team, if it is longer than 24 hours (3600 * 24) it deletes this account.

    
22.08.2014 / 14:14