在没有 javascript 的情况下在 PHP 中模拟后退按钮 [英] Simulating a back button in PHP without javascript

查看:57
本文介绍了在没有 javascript 的情况下在 PHP 中模拟后退按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个后退"按钮,但不使用 Javascript.我已经想到了一种可能的方法:

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

使用会话变量(例如 $_SESSION['http_referer']),每次加载时都会在每个页面上更新,

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

  • 将其内容保存到变量(例如 $lastPage)(以供进一步使用在当前页面)

  • saving it's content to a variable (e.g. $lastPage) (for further use in the current page)

分配给它$_SERVER['REQUEST_URI']

但我不确定这是多么有效(或低效).至少是正确的吗?

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

推荐答案

如果用户只能返回您的站点,那么最好在您存储在会话中的堆栈中跟踪他们访问过的页面,而不是_SERVER[HTTP_REFERER].当用户点击返回"按钮时,您可以重定向到堆栈顶部的页面(页面加载完成后添加到堆栈中,因此返回"按钮应使用上一页).请注意,这与真正的后退按钮完全不同.而是将其作为新页面添加到真实历史记录中.

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.

另请注意,在脚本执行期间写入 _SERVER[REQUEST_URI] 没有任何作用.

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

这篇关于在没有 javascript 的情况下在 PHP 中模拟后退按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆