[英]php session variable problem when unset
我做了一個函數來設置會話變量$ _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奇怪...我的錯誤是什么?
在每一頁上都是這樣:
您必須在顯示之前移動創建。
(它也不是很有用,因為您不會傳輸“閃存”(在創建后立即刪除)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.