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 变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Convert JSON integers and floats to strings(将JSON整数和浮点数转换为字符串)
in php how do I use preg replace to turn a url into a tinyurl(在php中,如何使用preg替换将URL转换为TinyURL)
all day appointment for ics calendar file wont work(ICS日历文件的全天约会不起作用)
trim function is giving unexpected values php(Trim函数提供了意外的值php)
Basic PDO connection to MySQL(到MySQL的基本PDO连接)
PHP number_format returns 1.00(Php number_Format返回1.00)