php - 发布数据并刷新页面

标签 php html http-post

我有一个编辑表单页面来编辑我的网站帖子。 它使用 post 方法到同一页面。 如果表单编译正确,则会显示一条祝贺消息。

问题:

当用户点击刷新按钮时,脚本会尝试将数据重新发布到页面。 有没有办法避免这种情况?

谢谢

卢卡

最佳答案

PRG 形态的大致轮廓是这样的:

if ( $_SERVER['REQUEST_METHOD'] == 'POST' )
{
     /// do your magic

     $_SESSION['error'] = "Thanks for your message!";

     // this should be the full URL per spec, but "/yourscript.php" will work
     $myurl = ...;

     header("Location: $myurl");
     header("HTTP/1.1 303 See Other");
     die("redirecting");
}

if ( isset($_SESSION['error']) )
{
     print "The result of your submission: ".$_SESSION['error'];
     unset($_SESSION['error']);
}

关于php - 发布数据并刷新页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5427428/

相关文章:

php - 使用 jquery 在同一个 ajax 请求中发送和接收数据

php - 就像 MySQL 和 PHP 中的逗号分隔列表一样

php - 我如何增加单元格 A1 :H1 in php excel 的高度

javascript - 如何通过javascript访问响应数据索引

iOS HTTP Post 不会运行 url

javascript - 后续的 POST 不会更新弹出窗口中的内容

php - 未定义的属性:stdClass::($variablename)

html - 文本周围的 CSS 框,设置框大小

html - 如何将垂直和水平居中的文本对齐到图像的右侧?

java - 通过 HTTPS 发送帖子 - 不工作