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

PHP - 使用 header() 传递 POST 变量?

PHP - Pass POST variables with header()?(PHP - 使用 header() 传递 POST 变量?)

本文介绍了PHP - 使用 header() 传递 POST 变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 header() 函数来创建重定向.我想显示错误消息.目前我正在通过 URL 作为参数发送消息,但这使它看起来很丑陋.

I'm trying to use the header() function to create a redirect. I would like to display an error message. Currently I'm sending the message as a parameter through the URL, however this makes it look quite ugly.

有没有办法将此值作为后变量传递?

Is there a way to pass this value as a post variable instead?

感谢任何建议.

谢谢.

推荐答案

Dan,您可以在 PHP 中启动和存储会话,然后将消息保存为会话变量.这使您不必在 HTTP 请求中传输消息.

Dan, You could start and store a session in PHP then save the message as a session variable. This saves you from having to transfer the message in an HTTP request.

//Start the session
session_start();

//Dump your POST variables
$_SESSION['POST'] = $_POST;

//Redirect the user to the next page
header("Location: bar.php");

现在,在 bar.php 中,您可以通过重新启动会话来访问这些 POST 变量.

Now, within bar.php you can access those POST variables by re-initiating the session.

//Start the session
session_start();

//Access your POST variables
$temp = $_SESSION['POST'];

//Unset the useless session variable
unset($_SESSION['POST']);

要了解有关会话的更多信息,请查看:http://php.net/manual/en/function.session-start.php

To read more about sessions, check out: http://php.net/manual/en/function.session-start.php

这篇关于PHP - 使用 header() 传递 POST 变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:PHP - 使用 header() 传递 POST 变量?

基础教程推荐