Redirect back to previous page in PHP
html, navigation, php
Solution
try this
header('Location: ' . $_SERVER['HTTP_REFERER']);
Note that this may not work with secure pages (HTTPS) and it's a pretty bad idea overall as the header can be hijacked.
or
header("location:javascript://history.go(-1)");
Problem
How do I redirect to a previous page using `header("Location:...")` ? The problem occurs when a user is scrolling down in a page to find a link for example, then clicks it - opens another page, clicks the link I've given "Go back to links (`header("Location:links.php");`)", but when the user clicks it, it will head to previous page but on the top part of the page. The user must scroll down again where he found the link he just clicked (which is frustrating). Is there a php code like the 'back'-button used in web browsers where you will go back to the exact location and page right before you click something else?