2010-03-29 29 views
0

在腳本結尾的關閉函數中使用session_write_close()時,PHP會死掉。沒有錯誤記錄,響應頭(螢火蟲)或數據(甚至是空白!)返回。我有完整的PHP錯誤報告與啓用STRICT和PHP 5.2.1。PHP session_write_close()會導致空的響應

我的猜測是,因爲session_write_close()在關閉後被調用 - 一些致命的錯誤正在遇到,它有可能在發送輸出或記錄任何東西之前崩潰PHP。

這只是發生在退出頁面上,我第一次:

... 
    //If there is no session to delete (not started) 
    if (! session_id()) 
    { 
     return; 
    } 

    // Get the session name 
    $name = session_name(); 

    // Delete the session cookie (if exists) 
    if (! empty($_COOKIE[$name])) 
    { 
     //Get the current cookie config 
     $params = session_get_cookie_params(); 

     // Delete the cookie from globals 
     unset($_COOKIE[$name], $_SESSION); 

     //Delete the cookie on the user_agent 
     setcookie($name, '', time()-43200, $params['path'], $params['domain'], $params['secure']); 
    } 

    // Destroy the session 
    session_destroy(); 
... 

然後2)做一些更多的東西3)發出重定向和4)最後,整個頁面後完成的register_shutdown_function();我前面放置運行並調用會話保存到數據庫的session_write_close()。結束。

由於此空白響應只發生在註銷我猜我沒有正確重新啓動會話導致session_write_close()在腳本結束時致命地死亡。

+0

你爲什麼需要session_write_close()呢? – zerkms 2010-03-29 00:23:41

+0

爲了確保會話保存在某些版本的PHP中,我想。 – Xeoncross 2010-03-29 00:24:50

+0

會話在腳本末尾自動寫入和關閉 – zerkms 2010-03-29 00:26:41

回答

0

奇怪。問題似乎是我在刪除cookie之前銷燬了會話。

這工作:

// Delete the session cookie (if exists) 
    if (! empty($_COOKIE[$name])) 
    { 
     //Get the current cookie config 
     $params = session_get_cookie_params(); 

     // Delete the cookie from globals 
     unset($_COOKIE[$name], $_SESSION); 

     //Delete the cookie on the user_agent 
     setcookie($name, '', time()-43200, $params['path'], $params['domain'], $params['secure']); 
    } 

    // Destroy the session ----------------------------------------- 
    session_destroy(); 

而這個殺死頁:

// Destroy the session ----------------------------------------- 
    session_destroy(); 

    // Delete the session cookie (if exists) 
    if (! empty($_COOKIE[$name])) 
    { 
     //Get the current cookie config 
     $params = session_get_cookie_params(); 

     // Delete the cookie from globals 
     unset($_COOKIE[$name], $_SESSION); 

     //Delete the cookie on the user_agent 
     setcookie($name, '', time()-43200, $params['path'], $params['domain'], $params['secure']); 
    } 

有誰知道爲什麼嗎?

相關問題