【发布时间】:2015-05-16 03:29:28
【问题描述】:
我不知道我的代码中的会话变量有什么问题...这是一个 sn-p:
文件 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>";
}
文件2(上面表格也提交的文件):
testing();
function testing(){
unset($_SESSION);
$_SESSION['testing']['testing'] = "<br>testing<br>";
header("Location: file1.php");
}
由于某种原因,在 file2 完成处理后操作后重定向回 file1 时,它没有打印出会话变量 $_SESSION['testing']['testing']...这是怎么回事???
【问题讨论】:
-
你有 session_start();在两个文件中?
-
是的,我仔细检查了...
-
你在调用/返回函数吗?
-
将错误报告添加到文件顶部,紧跟在打开 PHP 标记之后,例如
<?php error_reporting(E_ALL); ini_set('display_errors', 1);,然后是其余代码,看看它是否会产生任何结果。
标签: php forms redirect post session-variables