2012-04-29 93 views
-1

嗨即時創建一個簡單的註冊和登錄腳本在PHP中,但我得到這些錯誤時,我加載登錄頁面。session_start() - 無法發送會話cookie

警告:session_start()[function.session-start]:無法發送會話cookie - 在C:\ Users中已經發送(在C:\ Users \ s14 \ phase2 \ index.php:8開始的輸出) \ s14 \ phase2 \ index.php on line 10

Warning:session_start()[function.session-start]:無法發送會話緩存限制器 - 已發送的頭文件(輸出在C:\ Users \ s14 \ phase2 \的index.php:8)在C:\用戶\ S14 \階段2 \上線的index.php 10

從管線6到20的我的代碼

<form action="index.php" method=get> 
<h1 align="center" style="color:gray" >Welcome to this simple application</h1> 
<?php 
error_reporting(E_ALL & ~E_NOTICE); 
session_start(); 
if($_SESSION["logging"]) 
{ 
    print_secure_content(); 
} 
else { 
if(!$_SESSION["logging"]) 
{ 
$_SESSION["logging"]=true; 
loginform(); 
} 

回答

1

在回聲或輸出之前,您必須保持session_start()。您有這些HTML在session_start()運行之前輸出。

您的解決方案:

<?php 
/* Make sure this part is at the top */ 
error_reporting(E_ALL & ~E_NOTICE); 
session_start(); 
?> 
<!-- Now other --> 
<form action="index.php" method=get> 
<h1 align="center" style="color:gray" >Welcome to this simple application</h1> 
<?php 
if($_SESSION["logging"]) 
{ 
    print_secure_content(); 
} 
else { 
if(!$_SESSION["logging"]) 
{ 
$_SESSION["logging"]=true; 
loginform(); 
} 
?> 
+0

謝謝,我只是把<?PHP session_start(); ?>在html的頂部,錯誤似乎消失了。 – user1281921

+0

@ user1281921,也將錯誤報告放在頂部。 – Starx

0

session_start()必須在任何輸出之前調用。因此,如果您在任何HTML之前撥打session_start(),應該沒有問題。

相關問題