Go Back to Previous Page

Try this:

$previous = "javascript:history.go(-1)";
if(isset($_SERVER['HTTP_REFERER'])) {
    $previous = $_SERVER['HTTP_REFERER'];
}

in html:

<a href="<?= $previous ?>">Back</a>

The JavaScript code is initialize as fallback for HTTP_REFERER variable sometimes not work.


You can use a link to invoke history.go(-1) in Javascript, which is essentially equivalent to clicking the Back button. Ideally, however, it'd be better to just create a link back to the URL from whence the user was posted to the form - that way the proper "flow" of history is preserved and the user doesn't wonder why they have something to click "Forward" to which is actually just submitting the form again.

Tags:

Javascript

Php