我这段程序为什么会报错呢?

tyouzhou 2010-06-22 11:12:05
代码如下:

<?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

...全文
70 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
在-云端 2010-06-22
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 jlnuboy 的回复:]

引用 1 楼 cunningboy 的回复:

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 ……
[/Quote]

同意`~很明显在包含文件中已经有输出了!
jlnuboy 2010-06-22
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 cunningboy 的回复:]

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……
[/Quote] 很可能这里有输出了。不过我一般不用 header('location:index.php'); 我喜欢用echo "<script>location.href='index.php';</script>";
amani11 2010-06-22
  • 打赏
  • 举报
回复
utf-8编码吧?

如果conn.php文件没问题,,,你搜索utf8 BOM ,看怎么解决的


参考方案ultraedit 打开一个新文件然后另存为时选择“utf-8 无BOM”
foolbirdflyfirst 2010-06-22
  • 打赏
  • 举报
回复
利用编辑器把此文件另存为utf-8无bom头文件。
CunningBoy 2010-06-22
  • 打赏
  • 举报
回复
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.

21,887

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧