错误如下:Warning: Cannot modify header information - headers already sent by (output started at index.php:2) in cl.php on line 11Warning: Cannot modify header information - headers already sent by (output started at index.php:2) in cl.php on line 12Warning: Cannot modify header information - headers already sent by (output started at index.php:2) in cl.php on line 13代码:
<?php
if(isset($_POST['username'])){
$username=$_POST['username'];
$password=$_POST['password'];
$decide=$_POST['remember'];
include("../connectsql.php");
$searchl=mysql_query("select `account`,`password` from `stq` where `account`='$username' and `password`='$password'"); 
if(mysql_num_rows($searchl)==1){
$success="成功";
if($decide=="on"){
setcookie("loginmode","1",time()+3600*24*30);
setcookie("saccount","$username",time()+3600*24*30);
setcookie("spassword","$password",time()+3600*24*30);
}else{
}
}else{
$success="失敗";
}
}else{
echo("<script>document.location.href='/str/?mode=f'</script>");
}
mysql_close($con); 
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>登錄<?php echo($success);?></title>
</head>
<body>
<?php
if($success=="成功"){
echo("登錄成功,導向到主頁中");
echo("<script>setInterval(\"adddot("."'success')"."\",'1000')</script>");
}else{
echo("登錄失敗,重新導向到登錄頁面。");
echo("<script>setInterval(\"adddot("."'login')"."\",'1000')</script>");
}
?>
<div id="dot"></div>
<script>
var time=0;
function adddot(controll){
document.getElementById("dot").innerHTML+='.';
time++;
if(time==3 && controll=="success"){
document.location='/str/';
}else{
if(time==3){
document.location='/str/?mode=0';
}
}
}
</script>
</body>
</html>我setcookie放在HTML标签之前,怎么还出现错误呢?

解决方案 »

  1.   

    <?php
    if(isset($_POST['username'])){ 之前是否有空格空行,或者有bom头也会这样
    把你贴的这段代码再重新复制保存看看
      

  2.   

    不懂你的意思
    代码也就是主文中的代码了
    if之前的只是一个隔行,没有空格
    BOM头也确定消除了
    怎么会出现这情况呢..
      

  3.   

    那么看看php.ini output_buffering = off 是否是这样?改成 on
      

  4.   

    检查一下代码的最前面,也就是   <?php 之前是否有空格?,如果有的话,会发送头信息的。也
    就无法setcookie,或者session_start(),或者header()之类的....