Skip to main content

Go Back Button

12th October, 2022

Updated: 12th October, 2022

    Input button with inline JavaScript

    <input type="button" value="Go Back From Whence You Came!" 
    onclick="history.back(-1)" />

    This is totally obtrusive, but you could fix that by only appending this button through JavaScript.

    PHP

    If JavaScript isn't a possibility, you could use the HTTP_REFERER, sanitize it, and echo it out via PHP.

    <?php
      $url = htmlspecialchars($_SERVER['HTTP_REFERER']);
      echo "<a href='$url'>back</a>";
    ?>

    475b3121-505f-4393-b173-f7c6176885a0

    Created on: 12th October, 2022

    Last updated: 12th October, 2022

    Tagged With: