如果 JavaScript 被禁用,有什么方法可以链接到会话历史记录中的上一个文档?
可以使用 PHP 来简单地链接到 REFERRER 还是有更好的选择?
编辑:除此之外,可以保留以前的帖子变量吗?
如果 JavaScript 被禁用,有什么方法可以链接到会话历史记录中的上一个文档?
可以使用 PHP 来简单地链接到 REFERRER 还是有更好的选择?
编辑:除此之外,可以保留以前的帖子变量吗?
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.