1

我已经创建了一个函数来设置会话变量 $_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 奇怪...我的错误是什么?

4

1 回答 1

0

在每一页上都发生了这样的事情:

  • 进行会话
  • 显示闪光灯
  • 删除闪光灯
  • 创造价值的“闪光”

您必须在显示之前移动创建。

(它也不是很有用,因为你不传输'flash'(它在创建后立即删除)

于 2011-09-21T10:18:02.220 回答