2011-09-25 24 views
0

這個if語句已被棄用PHP ---如果(!session_is_registered過時?

if(!session_is_registered('firstname')){ 
header("location: index.php"); // << makes the script send them to any page we set 
} else { 
print "<h2>Could not log you out, sorry the system encountered an error.</h2>"; 
exit(); 
} 

if (isset($_SESSION['firstname'])){ 
header("location: index.php"); // << makes the script send them to any page we set 
} else { 
print "<h2>Could not log you out, sorry the system encountered an error.</h2>"; 
exit(); 

取代了它的初始代碼連接到我的logout.php腳本時。然後我去鏈接logout.php,這是顯示「無法登出你,對不起系統遇到錯誤。」

這是正確的解決方案,因爲我沒有問題的代碼

+0

如果有可能爲'$ _SESSION [ '姓名']'爲空,但設置,嘗試'array_key_exists( '姓名',$ _SESSION)'此外,它出現在第一例如,如果變量不存在,則重定向;如果存在,則重定向。這是你的預期行動? –

回答

1

根據您的第一個片段,我覺得你在邏輯上是失敗的。

嘗試:

if (!isset($_SESSION['firstname'])){ 
    header("location: index.php"); // << makes the script send them to any page we set 
} else { 
    exit('<h2>Could not log you out, sorry the system encountered an error.</h2>'); 
}