2017-08-30 93 views
0

我正在使用此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; 
} 
+0

向我们展示您设置和取消会话的代码请 –

+0

我发现它与PHPSESSID-cookie有关。我怎样才能禁用这个cookie将被设置? –

回答

0

我固定它。这是由于php.ini文件中的PHP 7.1发生了变化。只要我将我的PHP版本降级到PHP 7.0,一切都正常工作。

我希望这会帮助很多人。至少你现在有了一些起点。

+0

你知道ini文件中的变化是什么吗?这将有所帮助! –