我正在使用此Flash Messages Script作为简单的重定向和Flash消息系统。 一切工作正常我的Apache本地主机,但只要我上传到服务器(也是Apache)它不起作用。它设置会话并正确显示消息,但不会取消之后的消息。现在,我在我的网站上有大量“Flash消息”,除非您关闭浏览器以强制解除所有会话,否则它们会越来越多。Flash消息不会消失PHP
我已经阅读过千次的文档,还在服务器上的Flash Messages脚本中搜索了任何错误。我找不到任何东西。
也许你们可以帮助我。我将部署我的网站的主机是strato.com。
编辑:我在浏览器信息中发现了一个叫做PHPSESSID的cookie。也许这可能是有帮助的。
构造:
public function __construct()
{
// Generate a unique ID for this user and session
$this->msgId = sha1(uniqid());
// Create session array to hold our messages if it doesn't already exist
if (!array_key_exists('flash_messages', $_SESSION)) $_SESSION['flash_messages'] = [];
}
清除会话功能:
protected function clear($types=[])
{
if ((is_array($types) && empty($types)) || is_null($types) || !$types) {
unset($_SESSION['flash_messages']);
} elseif (!is_array($types)) {
$types = [$types];
}
foreach ($types as $type) {
unset($_SESSION['flash_messages'][$type]);
}
return $this;
}
加入会议:
public function add($message, $type=self::defaultType, $redirectUrl=null, $sticky=false)
{
// Make sure a message and valid type was passed
if (!isset($message[0])) return false;
if (strlen(trim($type)) > 1) $type = strtolower($type[0]);
if (!array_key_exists($type, $this->msgTypes)) $type = $this->defaultType;
// Add the message to the session data
if (!array_key_exists($type, $_SESSION['flash_messages'])) $_SESSION['flash_messages'][$type] = array();
$_SESSION['flash_messages'][$type][] = ['sticky' => $sticky, 'message' => $message];
// Handle the redirect if needed
if (!is_null($redirectUrl)) $this->redirectUrl = $redirectUrl;
$this->doRedirect();
return $this;
}
向我们展示您设置和取消会话的代码请 –
我发现它与PHPSESSID-cookie有关。我怎样才能禁用这个cookie将被设置? –