使用PHP将POST数据从一个网页传递到另一网页 [英] Passing POST data from one web page to another with PHP

查看:161
本文介绍了使用PHP将POST数据从一个网页传递到另一网页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

搜索没有找到类似的问题,因此:如何将PHP用于生成一个页面的POST数据从该页面传递到另一个PHP生成的页面?我有:

Searching did not find a similar question, so: How can POST data used by PHP to generate one page be passed from that page to another PHP generated page? I have:

  • 第1页上的表单,该表单通过POST将数据发送到PHP脚本.
  • 第2页由该脚本生成,并使用第1页上的条目和后端数据库显示由外部程序生成的一个或多个图形.该页面还具有另一种形式,其中包含用于使用新选项重新生成图形的选项(例如,放大或截断图形).
  • 如果需要,将使用从页面1和2粘贴在一起的POST数据,使用相同的PHP脚本生成第3页.除图形外,其基本外观与第2页相同.
  • 第4、5、6 ...页应以与第3页相同的方式生成.

那么,如何将用于生成第2页的POST数据放入第3页的POST数据中?

So, how can I put the POST data used to generate page 2 into the POST data for page 3?

由于组织政策的原因,不能使用cookie(因此会话不可行). GET是不可取的,因为我们不希望输入显示在URL中.

Due to organizational policy, cookies can't be used (so sessions are not feasible). GET is undesirable because we don't want the input to show in the URL.

推荐答案

我记得很久以前就在这个问题上苦苦挣扎,想知道为什么我根本无法使用修改后的POST标头重定向.原因是重定向实际上被认为是GET.

I recall struggling with this issue long ago, wondering why I simply couldn't redirect with a modified POST header. The reason is a redirect is actually considered a GET.

无论如何,您都需要将post变量存储在隐藏字段中.

Regardless, you need to store the post variables in hidden fields.

<input type="hidden" name="someValueFromPageOne" value="blah">

我建议您为每种表单的所有字段名称加上前缀,以便在合并阶段最后轻松区分它们.

I would recommend prefixing all your field names from each form so that its easy to tell them apart during your consolidation phase at the end.

<input type="hidden" name="pageOne_firstName" value="Joe">
<input type="hidden" name="pageTwo_streetNumber" value="22">

正如其他人所提到的那样,使用会话持久化数据是一种可能,但是这成为维护临时状态的非常复杂的问题,如页面刷新或使用后退"按钮之类的事情可能难以维护.除非您遇到极端情况,否则使用字段来持久保存数据要容易得多,因为它们可以在刷新和其他浏览器行为中幸存下来.

As others have mentioned, persisting data using sessions is one possibility, but this becomes a very complex matter of maintaining temporary state which things like page refreshes or using the back button can make difficult to maintain. Unless you're facing an extreme case, it's much easier to persist data using fields since they survive refreshes and other browser behaviour much more easily.

这篇关于使用PHP将POST数据从一个网页传递到另一网页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆