dtqqq24248 2011-10-14 03:25
浏览 8
已采纳

在没有javascript的情况下在PHP中模拟后退按钮

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,

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

  • assigning to it the value of $_SERVER['REQUEST_URI']

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

  • 写回答

1条回答 默认 最新

  • duanjue7745 2011-10-14 03:29
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题