Php 会话变量有什么问题

Php 会话变量有什么问题,php,forms,redirect,post,session-variables,Php,Forms,Redirect,Post,Session Variables,我不知道代码中的会话变量有什么问题……下面是一个片段: 文件1: display_test(); function display_test(){ if(isset($_SESSION['testing']['testing'])) echo $_SESSION['testing']['testing']; echo "<br><br><br><form id=\"current_juices_form\" m

我不知道代码中的会话变量有什么问题……下面是一个片段:

文件1:

display_test();

    function display_test(){
        if(isset($_SESSION['testing']['testing'])) echo $_SESSION['testing']['testing'];

        echo "<br><br><br><form id=\"current_juices_form\" method=\"post\" action=\"file2.php\">
                <input type=\"submit\" />
             </form>";
    }
display_test();
功能显示测试(){
如果(isset($_会话['testing']['testing'])echo$_会话['testing']['testing']);
回声“


"; }
文件2(上述表格所提交的文件):

测试();
功能测试(){
取消设置($_会话);
$\会话['testing']['testing']=“
测试
”; 标题(“位置:file1.php”); }

由于某些原因,当file2处理完post操作后重定向回file1时,它没有打印出会话变量$\u session['testing']['testing']……发生了什么事?

您需要先初始化$\u session['testing']

function testing(){
    if (!isset($_SESSION['testing'])) {
        $_SESSION['testing'] = Array();
    }

    $_SESSION['testing']['testing'] = "<br>testing<br>";
    header("Location:  file1.php");
}
功能测试(){
如果(!isset($\u会话['testing'])){
$\u会话['testing']=Array();
}
$\会话['testing']['testing']=“
测试
”; 标题(“位置:file1.php”); }
或者您也可以这样做:

function testing(){        
    $_SESSION['testing'] = Array('testing' => "<br>testing<br>");
    header("Location:  file1.php");
}
函数测试(){
$\u会话['testing']=Array('testing'=>“
testing
”); 标题(“位置:file1.php”); }
您有会话启动()吗;在这两个文件中?是的,我仔细检查了…你在调用/返回函数吗?在打开PHP标记后立即在文件顶部添加错误报告,例如
。我知道你在说什么,但在我的代码的其他部分,我从未初始化过二维会话变量,它们总是有效…我发布了其他代码,但它属于保密协议。。
function testing(){        
    $_SESSION['testing'] = Array('testing' => "<br>testing<br>");
    header("Location:  file1.php");
}