这是我的代码:
class Session {
public static function exists($name) {
return (isset($_SESSION[$name])) ? true : false;
}
public static function get($name) {
return $_SESSION[$name];
}
public static function put($name, $value) {
return $_SESSION[$name] = $value;
}
public static function delete($name) {
if(self::exists($name)) {
unset($_SESSION[$name]);
}
}
public static function flash($name, $string = null) {
if(self::exists($name)) {
$session = self::get($name);
self::delete($name);
return $session;
} else if ($string) {
self::put($name, $string);
}
}
}
在本地mamp服务器上运行时,会话未设置,但在实时服务器上运行时则不会。在运行flash方法时,会话仍然存在,并且在刷新page.eg后,$ string仍然保留在register.php中我有:
Session::flash('home', 'User has been registered and can now log in!');
Redirect::to('index.php');
并在index.php中:
if(Session::exists('home')) {
echo '<p>', Session::flash('home'), '</p>';
}
任何意见都会受到赞赏。