发布数据和刷新页面 [英] Post data and refresh page
问题描述
我有一个编辑页面来编辑我的网站帖子。
它使用post方法到同一页面。
如果表单编译正确,则显示恭喜您的消息。
问题: 当用户点击刷新按钮时,脚本会尝试再次将数据重新发布到页面。 谢谢 Luca PRG模式的大纲如下: I have an edit-form page to edit my website posts.
It uses post method to the same page.
If the form is compiled correctly shows up a congrats message. The problem: When users hit the refresh button the script tries to repost the data again to page.
Is there a way to avoid this? thanks Luca The general outline of the PRG pattern is this:
这篇关于发布数据和刷新页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
有没有办法避免这种情况?
<$ c ($ _SERVER ['REQUEST_METHOD'] =='POST')
{
///做你的魔法
$ _SESSION ['error'] =感谢您的留言!;
//这应该是每个规范的完整URL,但/yourscript.php可以工作
$ myurl = ...;
header(Location:$ myurl);
头(HTTP / 1.1 303 See Other);
die(重定向);
if(isset($ _ SESSION ['error']))
{
print提交结果:。$ _ SESSION ['error ];
unset($ _ SESSION ['error']);
}
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']);
}