2017-08-30 135 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文件中的變化是什麼嗎?這將有所幫助! –