由于我的问题(Previous question)无疑是以大多数用户认为“伙计,这是tl;dr”的方式提出的,所以让我说得更简单一些。我想使用post-redirect-get模式来避免用户刷新网站和重新提交数据等。我明白,为了做到这一点,我必须将用户从html表单重定向到php处理脚本,并返回到显示处理后数据的新站点(或原始html表单站点)。
现在我的问题来了。我如何从我的php中取回我处理过的数据?我不明白GET部分...目前,我不知道如何在没有include 'site.html';
的漂亮的html显示(视图)页面中显示php生成的数据。这个例子也不是我要找的:Simple Post-Redirect-Get code example。下面示例中的代码只是将我重定向到当前页面。
发布于 2018-06-12 04:51:23
我希望这会有所帮助,因为我也花了很长时间才弄明白。我像这样测试我的理解力。我有两个php页面,第一个页面(prg1.php)将表单发送到数据库,action设置为第二个页面(prg2.php)。prg2.php检查POST数据,更新数据库,并发出一个重定向到prg1.php,其中包含我需要作为GET变量传回的任何内容。prg2.php如下所示
<?php
if (isset($_POST['gameid'])){
// process the data, update the database
$gameid = htmlspecialchars($_POST['gameid']);
$playerid = htmlspecialchars($_POST['playerid']);
$message = htmlspecialchars($_POST['message']);
//redirect, after updating the database
$getinfo = '?gameid=' . $gameid . '&playerid=' . $playerid;
header("Location: prg1.php" . $getinfo );
exit();
}
?>
发布于 2013-08-02 21:10:28
您可以尝试如下所示:
/****************************************/
/* Fetch my data. */
/****************************************/
$mydata = $_GET["data"];
/****************************************/
/* Has to be sent before anything else! */
/****************************************/
header( 'Location: http://www.yoursite.com/index.php?data='.$mydata );
https://stackoverflow.com/questions/18017551
复制相似问题