Php 为什么不';我没有看到我在第一个脚本中设置的请求变量吗?

Php 为什么不';我没有看到我在第一个脚本中设置的请求变量吗?,php,request,superglobals,Php,Request,Superglobals,当我试图从我在第一个脚本中设置的$\u请求[]数组中检索变量status时(然后执行重定向),我只看到一个警告未定义索引:status。为什么呢 <?php $_REQUEST['status'] = "success"; $rd_header = "location: action_script.php"; header($rd_header); ?> action script.php 您要查找的是: 您要查找的可能是发送

当我试图从我在第一个脚本中设置的
$\u请求[]
数组中检索变量
status
时(然后执行重定向),我只看到一个警告
未定义索引:status
。为什么呢

<?php
        $_REQUEST['status'] = "success";
        $rd_header = "location: action_script.php";
        header($rd_header);
?>


action script.php


您要查找的是:



您要查找的可能是发送GET参数:

$rd_header = "Location: action_script.php?status=success";
header($rd_header);
可通过以下方式在
action\u script.php
中检索:

$_GET['status'];

在这种情况下,您不需要会话或cookie,但是您必须考虑这样一个事实:用户可以轻松地编辑GET POST。

< P>这是因为您的<代码>标题())/代码>语句将用户重定向到一个全新的URL。任何
$\u GET
$\u POST
参数都不再存在,因为我们不再在同一页上

你有几个选择

1-首先,您可以使用
$\u SESSION
跨页面重定向持久化数据

session_start();
$_SESSIONJ['data'] = $data; 
// this variable is now held in the session and can be accessed as long as there is a valid session.
2-重定向时向URL附加一些get参数-

$rd_header = "location: action_script.php?param1=foo&param2=bar";
header($rd_header);
// now you'll have the parameter `param1` and `param2` once the user has been redirected.

对于第二种方法。这是一种从名为
http\u build\u query()

的数组中创建查询字符串的方法,因为在头语句中没有传递任何参数。。。这是一个全新的URL,带有一个干净的
$\u REQUEST
变量。如果你把一张钞票放在一个口袋里,如果你在另一个口袋里找不到它,你会感到惊讶吗?@Lix如何使用header函数发送参数?我在报纸上看不到doc@YourCommonSense是的,会的!我经常忘记把钞票放进哪个口袋不是会话..但是作为请求变量发送参数不要忘记使用正确的编码与
http\u build\u query
:对于GET,这是RFC 3986.+1,用于提及
$\u GET
请求中的数据“信任”问题。永远不要相信那些用户!;)
session_start();
$_SESSIONJ['data'] = $data; 
// this variable is now held in the session and can be accessed as long as there is a valid session.
$rd_header = "location: action_script.php?param1=foo&param2=bar";
header($rd_header);
// now you'll have the parameter `param1` and `param2` once the user has been redirected.