PHP - Pass POST variables with header()?(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 变量?
基础教程推荐
- 在PHP中根据W3C规范Unicode 2022-01-01
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
- 如何替换eregi() 2022-01-01
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
- PHP 类:全局变量作为类中的属性 2021-01-01
