代码如下:<?php
session_start();
include('../inc/conn.php');
opendb();
$action = $_REQUEST["action"];
if ($action = "admin_login")
{
$username = $_POST["username"];
$password = $_POST["password"];
$vertifycode = $_POST["vertifycode"];
if ( !$username && !$password && !$vertifycode)
{
echo "<script>alert('登陆信息填写不完整!请返回重新填写!');history.go(-1);</script>";
exit;
}
if ($vertifycode != $_SESSION['VCODE'])
{
echo "<script>alert('验证码填写错误!请返回重新填写!');history.go(-1);</script>";
exit;
}
$sql = "select * from Admin where name = '".$username."' and password = '".md5($password)."'";
$result = mysql_query($sql);
$counts = mysql_num_rows($result);
if ($counts == 0 )
{
echo "<script>alert('用户名或密码错误!请返回重新填写!');history.go(-1);</script>";
exit;
} else {
header('location:index.php');
$_SESSION['username'] = $username;
}
}
?>错误如下:Warning: Cannot modify header information - headers already sent by

解决方案 »

  1.   

    include('../inc/conn.php');中是不是已经有header输出了?以下摘抄自PHP帮助文件: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.
      

  2.   

    利用编辑器把此文件另存为utf-8无bom头文件。
      

  3.   

    utf-8编码吧?如果conn.php文件没问题,,,你搜索utf8 BOM ,看怎么解决的
    参考方案ultraedit  打开一个新文件然后另存为时选择“utf-8 无BOM”
      

  4.   

     很可能这里有输出了。不过我一般不用 header('location:index.php'); 我喜欢用echo "<script>location.href='index.php';</script>";