ページ間でメッセージを保存するために、セッション変数 $_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を自分のページに直接入れて動作します..奇妙なことに...私の間違いは何ですか?