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

Asked

Viewed 1,111 times

5

Well, when registering on the site the user has its ACTIVE set to 0, so with the code I posted in the answer of the question link below I can update the ACTIVE to 1: How to enable a user’s email registration?

But if the user does not activate the data they will continue occupying space in my database. So someone can just fill my bank with emails.

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

4 answers

9

You can create a script that will be run by the server at any given time to remove users with value from the table ativo=0 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 - Linux - or the task scheduler - windows - to run the verification script.

  • 2

    Hi, Gustavo, I took the liberty of editing your reply to make it more affirmative and less interrogatory. I also added links to documentation. Give a check on the guide [Answer].

  • Thanks for answering. I don’t know how to link php and Windows task scheduler. I’ll have to study about that. Is this answer I posted valid? Works well.

  • 1

    Got it! : 3 Uhu

7

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

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

  • Call this PHP with require_once some (s) line(s) before making activation. This can be done independently and concomitantly to the following two techniques, and serves to eliminate the registration even if the scheduled task has not run at that time;

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

  • and if you don’t have access to cron or another form of scheduling, put a counter that runs this PHP with include in another PHP that is usually accessed on the site. For example, every n accesses, PHP includes the query script. (can do all access as well, but because of performance it is usually not necessary to execute at all times).

  • Hello Bacco, thank you for answering. I can come up with the logical processes mentally and once I see the codes I understand easily, but I’m not a programmer yet, so I need and look for answers in practice. I know that no one has an obligation to keep building scripts for me, that’s why I’m chasing, I’m studying, I’m not just waiting for everything to be ready. But for example, I don’t know how to link php and Windows task scheduler, I’ll have to study about it. Is this answer I posted valid? Work...

  • @Iwannaknow with what I proposed, you don’t need the scheduler. It would be good to add the DB you are using in the question tags, because it is better to give examples. At least the SQL of how to delete can be exemplified well, but for that it would be good to post at least the structure of the database in the question too.

  • I understand, I just said in general that without codes I keep breaking my head. But I appreciate it because they guide me on what I have to look for and what I have to study. I added the tag. Grateful.

  • Got it! : 3 Uhu

3


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

I managed to resolve the situation this way:

First I did this:

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

So when the user tries to log in the code below check if the asset is 0 or 1. If it is 0 and has not passed 24 hours of the registration time I ask him to access the email to activate, if it has passed 24 hours then I delete from the table that registration:

         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 it didn’t solve the situation, because the user could just never try to log in, so the data would still be in the database. So I did 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 happy with the result, thank you all for guiding me!

  • Since the above code is what generated a response for you, mark it as a response!

  • Okay, I’m gonna score!

2

Very simple, you will have to create an automation script that will be included on a main page of your site, every time someone enters, will run this script.

Look at this, you have to do a field in the user table called "last entry", and every time the user is logged in, you will have a script that will update this table with the time() current.

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

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

  • Thanks, I managed to do this yesterday. I’m trying to do a cron job now so that the script only runs from time to time. It seems simple, but while it is not working, take a look at the question: http://answall.com/questions/29914/como-fazer-com-que-um-script-em-php-insertion-uma-p%C3%A1gina-atrav%C3%A9s-de-um-requir

Browser other questions tagged

You are not signed in. Login or sign up in order to post.