PHP redirect – go back to previous page

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']}");


Last Updated On : 1st July 2009

Subscribe to get updates delivered to your inbox

11 Comments + Add Comment

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

  • What i the link contains a get method behind? How do i get it back too?

  • good,but not work in firefox???

  • i need

    go back to previous 2 page what i do..???

  • Works Good

    • Superman works good.

  • this not working..

  • Great Help!

  • hmm nice!

  • works too.

  • Great Topic, Works fine!

Leave a comment