沃梦达 / 编程问答 / php问题 / 正文

PHP用POST数据打开另一个网页

PHP open another webpage with POST data(PHP用POST数据打开另一个网页)

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

问题描述

我是 PHP 新手,我正在尝试做一些可能是不好的做法并且很可能是不可能的事情.我基本上只是在拼凑一些东西来测试我的知识,看看 PHP 能做什么.

I'm new to PHP and I'm trying to do something that may be bad practise and may well be impossible. I'm basically just hacking something together to test my knowledge and see what PHP can do.

我有一个网页,其中包含收集数据的表单.这被提交给一个 PHP 脚本,该脚本执行一堆处理 - 但实际上并不显示任何重要的东西.我想要的是,一旦处理完成,脚本就会告诉浏览器打开另一个页面,显示结果.

I have one webpage with a form that collects data. That is submited to a PHP script that does a bunch of processing - but doesn't actually display anything important. What I want is that once the processing is done, the script then tells the browser to open another page, where the results are displayed.

我知道我可以使用 header('Location: page.php'); 但我不知道如何提供 POST 数据.我怎样才能做到这一点?或者,还有其他方法可以告诉浏览器打开另一个页面吗?

I know I can use header('Location: page.php'); but I can't work out how to provide POST data with this. How can I do that? Alternatively, is there another way to tell the browser to open another page?

我从回复中得到的是,可能使用各种黑客来做到这一点,但我最好将处理和显示代码放在一个文件中.我对此很满意;这比什么都重要.

What I'm taking from the responses is that it's possible to do this using various hacks but I'd be better off to just have the processing and the display code in one file. I'm happy with that; this was an experiment more than anything.

推荐答案

真的需要处理完再调用另一个页面吗?我可能会做以下事情:

Is it really necessary to call another page after the processing is done? I'd probably do the following:

<form method="post" action="display.php">
...
</form>

display.php:

display.php:

if ($_POST) {
    require_once(process.php);
    process($_POST);
    display_results;
}

包含处理 post 请求所需的代码的 process.php.

with process.php containing the code necessary for processing the post request.

或者,您可以使用 cURL 库之类的东西将处理结果传递给您自己指定的页面.不知道这是否真的是你所追求的.

Alternatively, you could use something like the cURL library to pass the results of the processing to a page specified by yourself. Don't know if that's really what you're after though.

这篇关于PHP用POST数据打开另一个网页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:PHP用POST数据打开另一个网页

基础教程推荐