Detect whether the browser is refreshed or not using PHP

前端 未结 6 1414
慢半拍i
慢半拍i 2021-01-01 02:51

I want to detect whether the browser is refreshed or not using PHP, and if the browser is refreshed, what particular PHP code should execute.

6条回答
  •  遥遥无期
    2021-01-01 03:31

    If you mean that you want to distinguish between when a user first comes to the page from when they reload the page check the referrer. In php it is: $_SERVER["HTTP_REFERER"]. See if it is equal the page your script is running on. It may be the case that the client doesn't provide this information, if that happens you could set a cookie or session variable to track what the last requested page was.

提交回复
热议问题