开发者

Stop $_POST from having the same value when I refresh

开发者 https://www.devze.com 2023-01-02 10:19 出处:网络
When a vote value is changed, the form POSTs the change, then refreshes the page. This is called on the top of the page upon load:

When a vote value is changed, the form POSTs the change, then refreshes the page. This is called on the top of the page upon load:

  if (isset($_POST['q'.$question_id]))
    {
    $user->updateQuestionVotes($question_id, $_POST['q'.$question_id]);
    }

Why does it update every time I refresh after the first time? Do I need to unset it some开发者_开发知识库how?


Because that's the natural behavior of every browser. You need to redirect the user to the same page so that the POST values will not be in the header anymore.

Have you tried this?

header("Location: /back/to/same/page");

This will redirect the user to whatever page they need to land back on, removing any POST parameters that they sent. Any time you refresh a page, it uses the same headers as before, which means the POST content will still be there.

0

精彩评论

暂无评论...
验证码 换一张
取 消