Simulating a back button in PHP without javascript

巧了我就是萌 提交于 2019-12-12 04:44:35

问题


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:


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.



来源:https://stackoverflow.com/questions/7762732/simulating-a-back-button-in-php-without-javascript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!