How to avoid resending data on refresh in php

前端 未结 6 2093
心在旅途
心在旅途 2020-12-05 16:12

I have a page \"index.php\" where i have a link called \"add_users.php\". In \"add_users.php\", I accept user information and come back to the same page \"index.php\" where

6条回答
  •  鱼传尺愫
    2020-12-05 16:41

    I think that using sessions is best way to prevent this problem

    session_start();
    if(!isset($_SESSION['s'])){
      $_SESSION['s'] = true;
    };
    
    if( !empty( $_POST ) && ($_SESSION['s']) )
    {
      //your code
     $_SESSION['s'] = false;
    }
    

    Afterwards you may use unset($_SESSION['s']) or destroy_session() if you want users to be able to post something again.

提交回复
热议问题