Detect whether the browser is refreshed or not using PHP

前端 未结 6 1286
慢半拍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:16

    When the user hits the refresh button, the browser includes an extra header which appears in the $_SERVER array.

    Test for the refresh button using the following:

        $refreshButtonPressed = isset($_SERVER['HTTP_CACHE_CONTROL']) && 
                                $_SERVER['HTTP_CACHE_CONTROL'] === 'max-age=0';
    

提交回复
热议问题