session_start() - 无法发送会话cookie

时间:2012-04-29 23:42:31

标签: php mysql login

您好我在PHP中创建了一个简单的注册和登录脚本,但是当我加载登录页面时,我收到了这些错误。

警告:session_start()[function.session-start]:无法发送会话cookie - 已在C:\ Users \中发送的报头(在C:\ Users \ s14 \ phase2 \ index.php:8处开始输出)第10行的s14 \ phase2 \ index.php

警告:session_start()[function.session-start]:无法发送会话缓存限制器 - 已在C:\ Users \中发送的标头(输出从C:\ Users \ s14 \ phase2 \ index.php:8开始)第10行的s14 \ phase2 \ index.php

从我的代码的第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();
}

2 个答案:

答案 0 :(得分: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();
}
?>

答案 1 :(得分:0)

在任何输出之前必须调用

session_start()。因此,如果您在任何HTML之前调用session_start(),则应该没有问题。

相关问题