我将尽我所能解释这件事,我希望我能讲得通,因为英语不是我的第一语言。
假设我在第1页有一个表单,其中包含以下3个输入:

$_POST["name"];
$_POST["amount"];
$_POST["email"];

在第二个页面process.php上,我还有另一个输入:
$_POST["message"];

最后,在一个外部网站上有一个表单,我想在不必在他们的系统中键入任何内容的情况下发布:
<form action="display.php" method="post">
 <input type="text" name="name"><br>
 <input type="text" name="amount"><br>
 <input type="text" name="email"><br>
 <input type="text" name="message"><br>
<input type="submit">
</form>

然后我希望能够从process.php页面自动重定向到www.example.com/display.php,并自动提交表单,并且能够看到我刚输入的所有信息
display.php的外观示例:
Display.php
我无法访问外部网站或display.php上的代码,因此这意味着我无法编辑代码或使用任何会话。
我希望你能理解我,也希望你能帮助我,如果你能帮助我,我将不胜感激!
编辑:
我测试了一些在答案中给出的代码,看起来很有希望,但它没有将post数据传递到外部页面(这不是用于测试的外部页面)
下面是用于测试的代码:
进程.php
<?php
$_POST["name"] = "name";
$_POST["amount"] = "amount";
$_POST["email"] = "email";
$_POST["message"] = "message";

$post = array();
$post[] = "name=" . $_POST["name"];
$post[] = "amount=" . $_POST["amount"];
$post[] = "email=" . $_POST["email"];
$post[] = "message=" . $_POST["message"];

$ch = curl_init('http://localhost/display');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
header('Content-Type: text/html');
echo curl_exec($ch);
?>

显示.php
<?php
echo $_POST["name"];
echo $_POST["amount"];
echo $_POST["email"];
echo $_POST["message"];
?>

但不知为什么这不起作用?

最佳答案

这个怎么样?它假定名称、金额和电子邮件将发布到process.php
添加了故障排除代码。
进程.php

 <?php

 //[put database queries here]

 // $message = ??????????????????


$message = 'Message';

$post = array(
'name'=>$_POST['name'],
'amount'=>$_POST['amount'],
'email'=>$_POST['email'],
'message'=>$message);

$ch = curl_init('http://www.example.com/display.php');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_ENCODING,"");

header('Content-Type: text/html');
$data = curl_exec($ch);
echo $data;
?>

这是经过测试的,也很有效
是否重定向到实际站点。
<?php
$name = $_POST["name"];
$amount = $_POST["amount"];
$email = $_POST["email"];
$message = $_POST["message"];

echo <<< EOT
<html><head><style></style></head><body>
<form id="form" action="http://www.example.com/display.php" method="post">
<input type="hidden" name="name" value="$name"/>
<input type="hidden" name="amount" value="$amount"/>
<input type="hidden" name="email" value="$email"/>
<input type="hidden" name="message" value="$message"/>
</form>

<script>document.getElementById("form").submit();</script>
</body></html>
EOT;

?>

10-07 19:38
查看更多