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)
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).
<a href="/login.php?uri=<?= $_SERVER['PHP_SELF'] ?>">Log in</a>)