Free access to a page with set time

Asked

Viewed 87 times

0

Hello. I am new to creating websites and need help with the following situation: One customer requested the following situation: On the "Main Customers" page there should be a way to free up temporary access for those who want to see the portfolio that contains the products of these "Main Customers" and that this access lasts 5 days. The solution I found was that this page has a form where insert CNPJ and e-mail so that there is this access control. I thought after getting the information in the form send a link in the email and the person can access the page in question only in the 5 days as reported above and after that the link no longer work.

My question is, which way should I go?

As I informed I am new in this area. I know you will need BD, but I don’t even know where to start and what to use.

Could someone give a light?? - The page with form is already ready.

Thanks in advance.

  • Vc uses php or oq?

  • Html5+css+bootstrap

  • Without backend language you will not be able to do anything, nor send email.

  • I just need a kind of "step-by-step" of what to do to achieve the goal. Then I run after how to do it, even if I have to learn some language.

2 answers

3


You have already said that you have a form, so I will list a simple step-by-step without going into details, this you can easily find here at Sopt or if you have questions you can ask new specific questions. I will do using PHP which is the most common.

1. Database

First you must create a database (can be Mysql, which is quite common) with a table with 5 columns:

  • id: is the primary auto-increment column, which only keep telling the number of records as they are entered in the table.

  • email: where the user’s email will be stored. (type sweep)

  • CNPJ: where the user’s CNPJ will be stored. (type sweep)

  • token: where the token (a random single sequence type for each record, as if it were a password, e.g..: Ah2bd5h8Hjs). PHP itself has native resource to generate this. (type sweep)

  • dia: in this field you can store the day the user has registered, then check if he has more than 5 days. (type date or datetime)

2º. Send the form to a PHP file

After completing the form, you will submit it (send) to a PHP file (nome_do_arquivo.php) via POST (you can even use Ajax). This PHP file will receive the form fields (email and CNPJ) and will save the respective information to the BD (email, CNPJ, token and dia). Before writing to BD, you must generate the token and take the current date (the email and the CNPJ already comes from the form).

After recording the data in the BD, you will send an email message to the user with a link containing the email and the token, in this model:

http://seusite.com.br/pagina.php?email=email_do_usuario&token=token_que_foi_gerado

3º. Validating

The user will receive the message with the link. By clicking it will be redirected to your site according to the link. On the PHP page where the link leads, you will take the "email" and "token" parameters that are in the link URL and query in the BD if the two belong to the same record. If there is any divergence, it means that the link is invalid, then you can display a message "invalid link" or redirect (this depends on your choice).

If the query to the DB returns that the "email" and the "token" are correct, you do the last check: see if it’s been 5 days. For this you will use the value of the field dia returned from the BD consultation. For this you will have to use comparison between dates, see if the day that is in the BD table is more than 5 days from the current date. If it’s bigger, it means it’s been 5 days and you can display a message "Time-out" or redirect (at your discretion). But if in the comparison of the dates the difference is up to 5 days, it means that everything is OK and the user can proceed.

Edit: Above I mentioned doing the validation in 2 steps. But you can and even better do in 1 step. In the same query to BD, check at once if the email, token and the day check and have less than 5 days.

In short:

The above scheme is just a superficial catch, and at some points will involve data check etc., but it is not so complicated. I believe that even beginners, with a little research and effort, will be able to do it. Go step-by-step, testing each step until you reach the end point.

  ENVIO DO FORM PARA O PHP                     VALIDAÇÃO DO LINK
            ↓                                          ↓
    validar email e CNPJ                     captura os parâmetros
    (ver se são válidos)                    "email" e "token" da URL
      ↓            ↓                                   ↓
   não são      válidos                          consulta o BD
   válidos         ↓                              ↓         ↓
      ↓            ↓                          inválidos  válidos
 retorna erro      ↓                           ↓              ↓
(não faz nada)     ↓                      retorna erro  verifica o dia
                   ↓                     (não faz nada)  ↓          ↓
      gerar token e pegar data                           ↓          ↓
                   ↓                                 tem mais de  tem menos
             gravar no BD                              5 dias     de 5 dias
                   ↓                                     ↓          ↓
         enviar email com link                      retorna erro   acesso
            para o usuário                          (nega acesso)  liberado
                   ↓
                  FIM
         (exibe uma mensagem que
             deu tudo certo)
  • Thank you very much for the explanation... It’s all very clear... Now is to research and test until you get... vlw...

0

First you’ll need to choose a language backend to implement in the project.

After doing this, to control this 5-day access, you can do the following:

Create 2 more fields in the table, a field to detect if the user is active or not, that is, if you have not exhausted his 5 days and a field to store the date of when he made the registration. So whenever he logs in, you compare the registration date with the current date, and if the difference between them is greater than 5, you leave the field I mentioned earlier as disabled.

Browser other questions tagged

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