2010-11-10 123 views
0

我不能開始使用session_start()會議......我得到這個錯誤:PHP會話問題

Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /**************/index.php:5) in /**************/session.php on line 2 

這是我的session.php文件文件的內容:

<?php 
session_start(); 

if(((!isset($_SESSION['user']))) || (!isset($_SESSION['valid'])) || ($_SESSION['valid'] != -1 && $_SESSION['valid'] != 0 && $_SESSION['valid'] != 1)) 
$_SESSION['valid'] = 0; 

function destroy_session() 
{ 
    session_destroy(); 
} 
?> 

,我需要迫切解決這個問題!

+0

你確定''<?php'之前沒有空白嗎? – 2010-11-10 23:53:37

+0

http://stackoverflow.com/questions/1183726/headers-already-sent-in-php – Phil 2010-11-10 23:54:18

+0

這個文件是否被另一個文件包含? – lonesomeday 2010-11-10 23:55:27

回答

2

錯誤消息告訴您輸出開始

output started at /**************/index.php:5 

要麼調用session_start()發生在輸出之前(最好),或使用輸出緩衝(不太優選)

編輯:如果你不是意識到這個錯誤背後的原因,請閱讀PHP header()manual page

Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP. It is a very common error to read code with include(), or require(), functions, or another file access function, and have spaces or empty lines that are output before header() is called. The same problem exists when using a single PHP/HTML file.

1

聽起來像是你需要在您的代碼中早先包含該文件。主要是在輸出任何HTML或內容之前。