Autoincrement numeric variable in PHP on Refresh

前端 未结 4 1648
一生所求
一生所求 2021-01-24 08:56

How do I use PHP to auto-increment a numeric variable on page refresh?

Foe example, for $i=10 there is an output of this:

Page has be

4条回答
  •  遇见更好的自我
    2021-01-24 09:22

    You would need to store its state somewhere, perhaps in the $_SESSION.

    session_start();
    
    $i = isset($_SESSION['i']) ? $_SESSION['i'] : 0;
    
    echo ++$i;
    
    $_SESSION['i'] = $i;
    

提交回复
热议问题