Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

205
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!