我已经创建了一个函数来设置会话变量 $_SESSION['flash'] 以便在页面之间存储消息
function setFlash($string,$type="info") {
switch ($type) {
case "warning":
$_SESSION['flashtype'] = "warning";
break;
case "error":
$_SESSION['flashtype'] = "error";
break;
case "info":
$_SESSION['flashtype'] = "info";
break;
default:
$_SESSION['flashtype'] = "info";
break;
}
$_SESSION['flash'] = $string;
}
以及打印此消息的功能
function printFlash() {
echo $_SESSION['flash'];
unset($_SESSION['flash']);
}
我在每一页的顶部调用这个函数(当然在 session_start 之后)
问题是它什么都不打印,但是如果我评论“ unset($_SESSION['flash']);” 它在每一页打印消息。
我该如何解决?
解决了对不起我的错。
my page is something like this
include "func.inc.php"
session start
function editSomething {
that call setFlash()
}
include "template.php" (where printFlash() is called)
现在我将 printFlash 直接放在我的页面中并且可以正常工作..bah 奇怪...我的错误是什么?