【问题标题】:Having troubles with the refresh of a PHP page using form [duplicate]使用表单刷新 PHP 页面时遇到问题 [重复]
【发布时间】:2018-02-02 20:37:30
【问题描述】:

我有以下 PHP 代码

<html>

<head>
    <title>
        Test
    </title>
</head>

<body>
    <form name="test" action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="post">
        <input type="text" name="name">
        <br>
        <input type="submit" name="submit" value="Submit Form">
        <br>
    </form>

    <?php
      if(isset($_POST['submit']))
       {
        $name = $_POST['name'];
        echo "User Has submitted the form and entered this name : <b> $name </b>";
        echo "<br>You can use the following form again to enter a new name.";
       }
     ?>
</body>

</html>

工作正常,并回显用户在输入文本框中输入的文本。

代码还应该避免PHP_SELF 漏洞利用(我希望..)

但是如果我尝试在我的 Firefox 浏览器中刷新网页,则会出现一个警告,告诉我

要显示此页面,Firefox 必须发送重复的信息 执行的任何操作(例如搜索或订单确认) 早一点。

关于如何避免这种情况的任何建议?

【问题讨论】:

  • 表单提交后重定向。
  • 我需要将所有内容保存在同一页面中......
  • 所以重定向到同一个页面,有什么问题

标签: php forms http-post


【解决方案1】:
 if(isset($_POST['submit']))
    {
     $name = $_POST['name'];
     echo "User Has submitted the form and entered this name : <b> $name </b>";
     echo "<br>You can use the following form again to enter a new name.";
         echo ("<script>  window.location.href='http://YourPatch.com';</script>");


    }

【讨论】:

  • uhmmm .. 我试过了,但似乎不行...
  • 我更新了答案。如果你使用你的补丁就可以了。
猜你喜欢
  • 2017-04-17
  • 1970-01-01
  • 2019-01-22
  • 2016-08-13
  • 2019-01-24
  • 1970-01-01
  • 2013-10-15
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多