带参数的 PHP 标头重定向 [英] PHP Header Redirect with parameter
问题描述
所以我想使用基本的标题重定向将变量从一个页面带到另一个页面.这看起来很基本,但我看到的每个地方人们都在询问更复杂的情况,这使得它更难掌握.基本上,我有一个变量 $user = "root",我只想使用 Header("Location: query.php".$user);
So I want to use a basic header redirect to bring a variable from one page to another. This seems really basic, but everywhere I look people are asking about more complex situations and it makes it harder to grasp. Basically, I have a variable $user = "root" and I simply want to pass this to another page using Header("Location: query.php".$user);
首先,我想确保此重定向将正确发送我的变量.
First of all, I want to make sure that this redirect will send my variable correctly.
其次,我将如何在另一侧取回它.通常,如果我使用提交按钮发布到表单,我会使用这样的$user = ($_POST["user"]);
.在这种情况下,我会以类似的方式检索参数吗?
Second, how exactly will I retrieve it on the other side. Generally if I were using a submit button posting to a form, I would use something as this $user = ($_POST["user"]);
. Would I retrieve the parameter in a similar fashion in this case?
感谢您的帮助!
推荐答案
用于发送变量
$user = 'test';
Header("Location: query.php?user=".$user);
用于接收用户变量的值
$user = $_REQUEST['user'];
希望能帮助您解决问题.
I hope it will help to resolve your problem.
这篇关于带参数的 PHP 标头重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!