PHP使用POST数据打开另一个网页 [英] PHP open another webpage with POST data

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

问题描述

我是PHP的新手,我正在尝试做一些可能不好的做法,可能不太可能。我基本上只是一起窃取一些东西来测试我的知识,并看看PHP可以做些什么。



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



我知道我可以使用 header('Location:page.php'); 但我无法解决如何提供POST数据有了这个。我怎样才能做到这一点?另外,是否有另一种方式告诉浏览器打开另一个页面?



编辑:我从响应中得到的是可能使用各种黑客来做到这一点,但我最好只是将处理和显示代码放在一个文件中。我对此感到高兴;这是一个比实验更重要的实验。

解决方案

处理完成后真的需要调用另一个页面吗?我可能会做到以下几点:

 < form method =postaction =display.php> 
...
< / form>

display.php:

  if($ _POST){
require_once(process.php);
进程($ _ POST);
display_results;
}

包含process.php,其中包含处理post请求所需的代码。 p>

或者,您可以使用类似cURL库的内容将处理结果传递到您自己指定的页面。不知道这是否真的是你想要的。


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.

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.

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?

EDIT: 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:

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

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

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数据打开另一个网页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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