PHP - 通过标题()传递POST变量? [英] PHP - Pass POST variables with header()?
问题描述
我试图使用header()函数来创建重定向。我想显示一条错误消息。目前,我通过URL将消息作为参数发送,但这使得它看起来相当难看。
有没有办法将此值作为后置变量传递?
任何建议赞赏。
谢谢。
操作会话
//开始会话
session_start();
//转储您的POST变量
$ _SESSION ['POST'] = $ _POST;
//将用户重定向到下一页
header(Location:bar.php);
现在,在 bar.php
内,您可以通过重新启动会话来访问这些POST变量。
//开始会话
session_start();
//访问您的POST变量
$ temp = $ _SESSION ['POST'];
//取消设置无用的会话变量
unset($ _ SESSION ['POST']);
要详细了解会话,请查看: http://php.net/manual/en/function.session-start.php
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?
Any advice appreciated.
Thanks.
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.
Manipulating Sessions
//Start the session
session_start();
//Dump your POST variables
$_SESSION['POST'] = $_POST;
//Redirect the user to the next page
header("Location: bar.php");
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']);
To read more about sessions, check out: http://php.net/manual/en/function.session-start.php
这篇关于PHP - 通过标题()传递POST变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!