PHP redirect – go back to previous page

By | July 1, 2009

To go back to the previous page the superglobal variable $_SERVER can be used.


$_SERVER['HTTP_REFERER'] has the link to the previous page.

So to redirect simply :

#Method to go to previous page
function goback()
{
	header("Location: {$_SERVER['HTTP_REFERER']}");
	exit;
}

goback();





Last Updated On : 1st July 2009

Related Post

12 thoughts on “PHP redirect – go back to previous page

  1. Tony

    The title should be “go forward to previous page” as if you cycle through with the back button, it redisplays all the intermediate pages.

Leave a Reply

Your email address will not be published. Required fields are marked *