Identifying number of hits on the page

Asked

Viewed 38 times

-1

I’m trying to perform a check of how many times a person performs access to a given page, but I do not know how to do it, I would like to perform this in PHP or Javascript.

First Access:

  • Display initial instructions

Second Access:

  • Display items, links, or other elements if the person followed the instructions on first access. (At this point, I know that further validations will be required to verify that the instructions have been correctly followed)

[...] (Other access)

  • Hello, since you said yourself you were a beginner, I suggest we start with the basics. Learn more about the language you will use (or languages); in addition, a good way is to use $_SESSION in PHP, you can create a counter and a counter value check to accomplish such a release.

  • I also suggest refactoring your question to clarify the doubt, and indicate the language you are using.

1 answer

0


An alternative using PHP (since the language to be used was not specified):

<?php

//Iniciar a sessão
session_start();

//Verificar se a variável de contador existe (caso não exista, será criada)
if(!isset($_SESSION['visit-counter']){
    $_SESSION['visit-counter'] = 1;
}

//Toda vez que a página for recarregada, o contador receberá +1
$_SESSION['visit-counter'] += 1;

if($_SESSION['visit-counter'] <= 1){
    //Código para exibir as orientações caso o contador seja menor ou igual à 1
}else{
    //Código para exibir o link caso o contador seja maior que 1
};

Other alternatives may be to use cookies, or asynchronous requests with AJAX, but I believe that the above code already solves the problem and is the most suitable for the case.

  • 1

    thank you so much for the reply, forgive me for the information fallta...the address I wanted was in java script or php...

  • add as an answer if it has really answered your question :D so other people searching for this type of information can already see that there is an accepted answer, and that maybe it can help them :)

Browser other questions tagged

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