我已经在这里和其他地方搜索了很多帖子,但似乎无法找到解决我的问题。 我有一个显示数据库条目的页面:database.php。这些条目可以用表单过滤。当我过滤它们,只显示我感兴趣的,我可以点击一个条目(作为一个链接),带我到该条目页(通过PHP GET)。当我在该条目页面(即“view.php?id = 1”)并点击后退按钮(返回到database.php)时,过滤器表单需要确认表单重新提交。有什么办法可以防止这种情况发生?防止表单重新提交后点击按钮
这里有一些(简化)代码示例:
database.php中:
<form>
<select>
<option>1</option>
<option>2
<option>
</select>
<input type="submit" name="apply_filter" />
</form>
<?php
if (isset($_POST[ "apply_filter" ])) { // display filtered entries
$filter = $_POST[ "filter" ];
$q = "Select * from table where col = '" . $filter . "'";
$r = mysql_query($q);
} else { // display all entries
$q = "Select * from table";
$r = mysql_query($q);
}
while ($rec = mysql_fetch_assoc($r)) {
echo "<a href='view.php?id=" . $rec[ "id" ] . "'>" . $rec[ "name" ] . "</a><br />"; // this is where the link to the view.php page is...
}
?>
现在提到,如果我点击链接,就带我到“view.php? ID =什么”。在该页面中,我刚刚从URL获得ID,以显示单个条目:
view.php:
<?php
$id = $_GET[ "id" ];
$q = "Select * from table where id = '" . $id . "'";
$r = mysql_query($q);
while () {
// display entry
}
?>
如果我现在打的返回按钮,在database.php中的形式(用于过滤DB结果的那个)需要确认重新提交。这不仅非常烦人,对我也无用。
我该如何解决这个问题?我希望代码示例和我的问题的解释是足够的。如果不让我知道,我会尝试指定。
** POST ** - > * ServerSide 302重定向* - > ** GET ** – scunliffe 2013-03-05 15:15:09
我知道有很多这个主题的帖子。浏览他们我无法弄清楚我自己的问题,所以我决定把它作为一个新问题。 – user1889382 2013-03-05 15:16:19
您可能想要使用'Post-Redirect-Get'模式,请参阅https://en.wikipedia.org/wiki/Post/Redirect/Get以及http://stackoverflow.com/questions/15288229/automatically-在浏览器中重新发送请求时使用后退按钮 – 2014-07-29 14:59:31