2014-01-08 139 views
0

我正在爲我創建的工具使用PHP會話。它允許您恢復先前存儲在數據庫中的可能啓動的會話。所有功能都按預期工作。PHP會話未清除?

不過,我提供一個鏈接,說:「新建會話」,它指向一個PHP頁面包含此代碼:

<?php 
session_start(); 
session_destroy(); 
$_SESSION = array(); 
unset($_SESSION); 
header('Location: wizard.php'); 
?> 

現在,當重定向回wizard.php,我有打印出所有會話詳細信息,並且仍包含前一會話的信息。

有什麼我在這裏失蹤?

Wizard.php以session_create()開頭;所以我會假設一旦它重定向它會創建一個新的會話ID和所有沒有發生。

感謝任何信息

+0

您需要取消它之前destroing它... – Goikiu

+0

我只是改變了這一切,並wizard.php仍含有相同的session_id,它已在運行該代碼塊之前。 – SBB

回答

1
<?php 
    // Initialize the session. 
    // If you are using session_name("something"), don't forget it now! 
    session_start(); 

    // Unset all of the session variables. 
    $_SESSION = array(); 

    // If it's desired to kill the session, also delete the session cookie. 
    // Note: This will destroy the session, and not just the session data! 
    if (isset($_COOKIE[session_name()])) { 
     setcookie(session_name(), '', time()-42000, '/'); 
    } 

    // Finally, destroy the session. 
    session_destroy(); 

    header('Location: wizard.php'); 
?> 

來自session_destroy Example 1

+0

謝謝,我認爲這與cookie沒有被清除有關。這工作完美。 – SBB

+0

高興地幫助你! :) – silentw