PHP - 通过 POST 重定向和发送数据

问题描述:

我有一个在线网关,需要提交带有隐藏字段的 HTML 表单.我需要通过没有任何 HTML 表单的 PHP 脚本执行此操作(我有数据库中隐藏字段的数据)

I have an online gateway which requires an HTML form to be submitted with hidden fields. I need to do this via a PHP script without any HTML forms (I have the data for the hidden fields in a DB)

通过 GET 发送数据:

To do this sending data via GET:

header('Location: http://www.provider.com/process.jsp?id=12345&name=John');

要通过 POST 发送数据吗?

And to do this sending data via POST?

您无法使用 PHP 执行此操作.

You can't do this using PHP.

正如其他人所说,您可以使用 cURL - 但是 PHP 代码会变成客户端而不是浏览器.

As others have said, you could use cURL - but then the PHP code becomes the client rather than the browser.

如果您必须使用 POST,那么唯一的方法就是使用 PHP 生成填充的表单并使用 window.onload 钩子调用 javascript 来提交表单.

If you must use POST, then the only way to do it would be to generate the populated form using PHP and use the window.onload hook to call javascript to submit the form.