views:

240

answers:

1

If JavaScript is disabled what's a way of linking to the previous document in the session history?

Can PHP be used to simply link to the REFERRER or is there a better alternative?

Edit: Further to this, can previous post variables be retained?

A: 

You're really mixing the idea of previous document in client session history vs. server session history.

Since Javascript is client-side, executing a history.back() renders the control to the browser, which then decides which page was last in the history (keeping in mind that the last page may not be a page within your domain). When you're using server-side PHP, the HTTP header referrer is whatever the browser supplied to you. If your server-side URI wasn't called as a result of an explicit click on a link, form GET/POST, etc. , your script probably won't get a referrer header value.

If you only want to capture the referrer within your site's domain, you can start maintaining a breadcrumb trail server-side (in the user's session). eg: $_SESSION['breadcrumbs'] = array( 'page1', 'page2', ... )

POST variables can be persisted in the SESSION too though I've never seen a good reason to do so. If you're trying to return an error message for a form and expect to get back the POST, you shouldn't be saving the state of the original POST.

Pras
Session is a bad idea : what if I open two tabs ?
Guillaume