First visit message on the site

0

I have a system that whenever the client logs in, counts another visit, and on the first visit a welcome message appears. But if the user reloads the page again or changes the tab and returns to the main page, the welcome message appears again. It just stops appearing if it shuts down and logs in again, which increases the hit counter.

I thought I would put a request on the close button of the message for the database to consider the message as a view and it will not appear any more, but I would like to know if it is possible to make the user login, when it changes the tab or reloads the page, the message disappears definitively without using the database. Is it possible?

    
asked by anonymous 13.09.2017 / 18:32

2 answers

0

I was able to do it here. Thanks for the help but now that I saw it was easier than I was thinking. I did so:

In validation:

if($nVisitas->visitas >= 1){
        $contagem = $nVisitas->visitas + 1;

        $visitas = $conecta->prepare("update users set visitas = '$contagem' where email = '$email'");
        $visitas->execute();
                    }

On the main page:

if($nVisitas->visitas == 0){
                echo "<p>Bem Vindo ao site!</p>";

                $visitas = $conecta->prepare("select * from users where email = '$email'" );
        $visitas->execute();
        $visitou = $visitas->fetch(PDO::FETCH_OBJ);


        $contagem = $visitou->visitas + 1;

        $visitante = $conecta->prepare("update users set visitas = '$contagem' where email = '$email'");
        $visitante->execute();

        }

In this way, the first time the user logs in, it will not increment in the validation, it will only increment in the main page that will pay a visit after the message code is already on the screen. So when I change the tab or reload the page, it no longer shows the message, since it has already increased a visit. I've been here to help someone if you have the same question.

    
14.09.2017 / 01:10
1

The script below will only run if there is no session.

if (!isset($_SESSION['visitado'])){ 
   //mensagem boas vindas
   echo "Bem-vindo";
   //script para contabilizar visita
   //cria uma sessão
   $_SESSION['visitado'] = session_id();
}
  

put the script within login validation

    
13.09.2017 / 19:20