1

This might be a nit-picking question, but still...

I'm going to have a "back" button/link on a 404 page. AFAIK it can be implemented with JavaScript history.go(-1) or with PHP using $_SERVER['HTTP_REFERER']

My question: what are pros and cons for one over the other?

frnhr
  • 12,354
  • 9
  • 63
  • 90

1 Answers1

0

The best method is to set a session variable (ie. PREVIOUS_REQUEST) on every request. This is the only sure method of retaining that information. This takes some work on your side, but atleast it's a sure bet.

The javascript history might be prohibited due to extreme security settings in the browser (ie. disabled javascript).

The $_SERVER['HTTP_REFERER'] value is also supplied by the browser, so this being filled is also not guaranteed.

$_SERVER['HTTP_REFERER'] could still be your best option, but do keep in mind its restrictions which you can find here: In what cases will HTTP_REFERER be empty

Community
  • 1
  • 1
Damien Overeem
  • 4,487
  • 4
  • 36
  • 55