2012-06-22 30 views
-3

我建立一個迷你型的CMS,但是當我嘗試使用會話我得到這個錯誤:PHP會話功能說棄用

推薦使用:功能session_is_registered()在index.php文件已經過時上線4條,其中,我使用的代碼是:

<?php 
session_start(); //Start the session 
define(ADMIN,$_SESSION['name']); //Get the user name from the previously registered super global variable 
if(!session_is_registered("admin")){ //If session not registered 
header("location:login.php"); // Redirect to login.php page 
} 
else //Continue to current page 
header('Content-Type: text/html; charset=utf-8'); 
?> 

它還說一些關於已經發出頭......

+3

[用於棄用session_is_registered替代]的可能重複(http://stackoverflow.com/questions/5286446/alternative-for-deprecated-session-已註冊) – ManseUK

+0

只需要一個[Google搜索](http://www.google.com/search?q=session_is_registered()+替代)即可找到[解決方案](http://stackoverflow.com/questions/) 2600905/PHP-替代到會話被登記)。所以。可能重複以及 – Havelock

回答

3

session_is_registered已被棄用,只是用isset檢查:

if(!isset($_SESSION['admin'])){ 

而對於header already sent通知,您應該確保在session_start()和任何head()函數之前沒有輸出。

如果您的display_errors配置處於打開狀態,則您的情況最多是由已棄用的通知引起的。

+0

最有可能的是,不推薦使用的警告是造成'頭已發送':) –

+0

@傑克是的,這是真的:) – xdazz

+0

嘿謝謝,它的工作:) –