federicot
federicot

Reputation: 12341

Simulating a back button in PHP without javascript

I need a "back" button but without the use of Javascript. I already thought of one possible approach:

Using a session variable (e.g. $_SESSION['http_referer']) which would be updated every time on every page whenever it's loaded,

But I'm not sure how efficient (or inefficient) this is. Is it at least correct?

Upvotes: 0

Views: 1475

Answers (1)

Explosion Pills
Explosion Pills

Reputation: 191749

If the user can only go back on your site it's much better to keep track of which pages they've visited in a stack you store in the session instead of _SERVER[HTTP_REFERER]. When the user clicks the "back" button, you can redirect to the page at the top of the stack (a page is added to the stack after it finishes loading, so the "back" button should use the previous page). Note that this is not the same as a real back button at all. Instead it is added to the real history as a new page.

Also note that writing to _SERVER[REQUEST_URI] during script execution does nothing.

Upvotes: 2

Related Questions