简体   繁体   English

如何获取从第一页到第三页的帖子值,作为帖子

[英]How to get post values from first page to third page ,as post

i have 3 pages我有 3 页

Page1.php,page2.php,page3.php

In page1.php, i have some hidden values, for example 'name'在 page1.php 中,我有一些隐藏值,例如“名称”

After the submission of page1.php, it will go to page2. page1.php提交后,会go到page2。

Then after some process in page2.php, it should need to automatically submit to page3.php(where page3.php is in another sever)然后在page2.php中的一些处理之后,它应该需要自动提交到page3.php(其中page3.php在另一个服务器)

Finally,when i print the $_POST variables in page3.php, i need to get the variable 'name'最后,当我在 page3.php 中打印 $_POST 变量时,我需要获取变量“名称”

You will want to look into sessions .您将需要查看会话

If you need them in POST, try this:如果您在 POST 中需要它们,请尝试以下操作:

$display = "";
$saveFields = array('one', 'two'); // whitelist of fields to add to the form hidden
foreach ($_POST as $key => $val) {
    if (!empty($val) && in_array($key, $saveFields)) 
        $display .= '<input type="hidden" name="'.$key.'" value="'.$val.'" />';
}

echo $display;

Should get you where you want to go.应该让您到达您想要的位置 go。 The whitelist just ensure's that random stuff is not injected that does not need to be.白名单只是确保不注入不需要的随机东西。

you could stick it in the session你可以把它贴在session

<?php
session_start();
if (!isset($_SESSION['count'])) {
  $_SESSION['count'] = 0;
} else {
  $_SESSION['count']++;
}
?>

or you could pass them in hidden vars on page2.php if it has a form...或者你可以在 page2.php 上的隐藏变量中传递它们,如果它有一个表单......

(1) Option is to add hidden input on page2 too. (1) 选项也是在 page2 上添加隐藏输入。

(2) Option is to set the value from page1's name into session and use it on page3 (2) 选项是将page1名称中的值设置为session并在page3上使用

There are several solutions:有几种解决方案:

  • PHP sessions PHP 会话
  • cookies cookies
  • passing arguments as GET/POST parameters将 arguments 作为 GET/POST 参数传递
  • storing data in database在数据库中存储数据

In simple cases passing arguments as GET parameter page2.php?name=... or using hidden form field is the best solution在简单的情况下,通过 arguments 作为 GET 参数 page2.php?name=... 或使用隐藏表单字段是最好的解决方案

This seems straightforward to me, page one has a hidden value called name .这对我来说似乎很简单,第一页有一个名为name的隐藏值。 Page 2 should retrieve the post $_POST['name'] and print it on page 2 as a hidden field.第 2 页应检索帖子$_POST['name']并将其作为隐藏字段打印在第 2 页上。 Once you post it to Page 3 you can retrieve it the same way $_POST['name'] .将其发布到第 3 页后,您可以以相同的方式检索它$_POST['name']

Realistically if the data is exactly the same and is being carried all the way to page 3, why do you even need it?实际上,如果数据完全相同并且一直被带到第 3 页,那您为什么还需要它呢? Can you not just declare it on page 3?你能不能只在第 3 页声明它?

Okay, the way I read this is that on your first page you have a UI with a form.好的,我读到这篇文章的方式是,在您的第一页上,您有一个带有表单的 UI。 The form is then submitted for processing to page 2. After processing is done, you want to redirect, if you will, the user to another site (or server, doesn't necessarily have to make a difference).然后将表单提交到第 2 页进行处理。处理完成后,如果您愿意,您希望将用户重定向到另一个站点(或服务器,不一定要有所作为)。

If I got that right, here is what you should do;如果我做对了,这就是你应该做的; instead of using the header();而不是使用 header(); function (php), print an empty page with a hidden form with all of the details you want to send over and use javascript to emulate the user 'submitting' the form. function (php),打印一个带有隐藏表单的空白页面,其中包含您要发送的所有详细信息,并使用 javascript 模拟用户“提交”表单。

< div style="display: none;"> <div style="display: none;">
< form action="https://mywebpage.com/myscript.php" method=POST> <form action="https://mywebpage.com/myscript.php" method=POST>
< input type=hidden name="key_1" value="value_1"> <输入类型=隐藏名称=“键_1”值=“值_1”>
< input type=hidden name="key_2" value="value_2"> <输入类型=隐藏名称=“键_2”值=“值_2”>
< input type=hidden name="key_3" value="value_3"> <输入类型=隐藏名称=“键_3”值=“值_3”>
< input type=submit id="formButton" style="visibility: hidden; "> < input type=submit id="formButton" style="visibility: hidden; ">
< script language="javascript"> <脚本语言="javascript">
document.getElementById("formButton").click() document.getElementById("formButton").click()
< /form> </form>
< /div> </div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM