Search code examples
phphtmluser-experiencebrowser-history

Stop page from being remembered in history after redirect


I have a page which when an a link is clicked (which must remain an a link, with no JavaScript), is redirected to a PHP script to perform a near instantaneous operation, and then sent back to the previous page.

The problem is, when the user clicks the back button, the page goes back to the page that had been loaded before the script was performed, and the user has to click the back button twice before they can get back to the sending page.

Is there any way to stop this? It isn't a nice user experience having to click the back arrow twice, and there must be a (relatively easy) way to stop this from happening.

Any help appreciated.


Solution

  • Send a 301 Header. header('HTTP/1.1 301 Moved Permanently'); - It must be sent before any output. Then whichever page you redirect to will replace the PHP page.