Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

207
Visualizações
Ho to go to the previous page refreshing and without saving actual in history

after some code has been executed, I want the user of my website to be redirected to the previous page of the provious page.

Ex.
Home Page -> LogIn Page (form) -> LogIn page (logging code) -> Home Page

At the moment I'm doing this with PHP and javascript as below:

echo "<script>history.go ( -2); Location.reload ()</script>";

This code is working as I want:
The user is visiting the website, then he want to login so it goes to the LogIn page, the form redirect to a service page and then I want to user to be redirected to the page he was reading (in the example the Home Page).

The problem is that in the browser hystory the user is able to see the service page, what can I do to solve the problem?
I need the user to be redirected, but also the page to be refreshed as in the menu the LogIn button need to be changed with the LogOut button.

Real:
Home Page -> LogIn Page (form) -> LogIn page (logging code) -> Home Page (reloaded)

In hystory:
Home Page -> LogIn Page (form) -> Home Page (reloaded)

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I would suggest that you use php redirects only, not javascript. Unless you’re using ajax, the responsibility lies with the server (and with ajax you wouldn’t be leaving the page anyway).

  1. Send current URI in GET request to login. (use the query string: <a href="/login.php?uri=<?= $_SERVER['PHP_SELF'] ?>">Log in</a>)
  2. Send URI along with other variables (user/pass) in login form submission (POST)
  3. Be sure to sanitize user input (URI)
  4. Process login info (including logging) and redirect to URI or redirect to a failure page (if desired)
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda