seeion_start()和header()不能用,求达人指教!??QQ21429503

beauty9235 2005-12-20 04:12:40
seeion_start()和header()不能用,求达人指教!??QQ21429503
数据库正常使用,环境winxp,apache,php5,mysql
我怀猜想是php.ini配置问题,但其它正常,就是这两个库函数不能用(其它的还不知道)

Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at C:\Apache2\htdocs\conn.php:4) in C:\Apache2\htdocs\checklogin.php on line 3

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\Apache2\htdocs\conn.php:4) in C:\Apache2\htdocs\checklogin.php on line 3

Warning: Cannot modify header information - headers already sent by (output started at C:\Apache2\htdocs\conn.php:4) in C:\Apache2\htdocs\checklogin.php on line 14

logo.php

<table width="100%" height="100%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<form action="checklogin.php" method="post"><td align="center" valign="middle"><table width="400" border="0" cellpadding="5" cellspacing="1" class="tablebg">
<tr class="tdbg">
<td colspan="2"><div align="center">Administrators Login</div></td>
</tr>
<tr class="tdbg">
<td><div align="center">Username</div></td>
<td><div align="center">
<input name="username" type="text" id="username">
</div></td>
</tr>
<tr class="tdbg">
<td><div align="center">Password</div></td>
<td><div align="center">
<input name="password" type="password" id="password">
</div></td>
</tr>
<tr class="tdbg">
<td colspan="2"><div align="center">
<input type="submit" name="Submit" value="Submit">
<input type="reset" name="Submit2" value="Clear">
</div></td>
</tr>
</table></td></form>
</tr>
</table>


checklogin.php

<?
require_once('conn.php');
session_start();
$username=$_POST['username'];
$password=$_POST['password'];
$exec="select * from shop where user='".$username."'";
if($result=mysql_query($exec))
{
if($rs=mysql_fetch_object($result))
{
if($rs->pwd==$password)
{
$_SESSION['adminname']=$username;
header("location:index.php");
}
else
{
echo "<script>alert('Password Check Error!');location.href='login.php';</script>";
}
}
else
{
echo "<script>alert('Username Check Error!');location.href='login.php';</script>";
}
}
else
{
echo "<script>alert('Database Connection Error!');location.href='login.php';</script>";
}

?>
...全文
153 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
ggltechggl 2005-12-22
  • 打赏
  • 举报
回复
header之前一定不能有空格和空行,還有echo ,print
helloyou0 2005-12-22
  • 打赏
  • 举报
回复
header之前不能有require_once或include之类的
------------------
检查一下你的require或include进来的文件里有没有输出,
注意在?>和<?之间的也是输出。

ob_start就是缓存输入的内容,要到flush或脚本结束的时候才会输入其中的内容,
这时候header之类已经执行过了,当然就没问题了
lwj213 2005-12-21
  • 打赏
  • 举报
回复
楼上所言极是
ccxxcc 2005-12-21
  • 打赏
  • 举报
回复
ob_start()是延缓向浏览器发送数据的开始函数,就是缓存
所以“headers already sent”错误就不会发生了
Cain 2005-12-21
  • 打赏
  • 举报
回复
把session_start()提到第一行
把header()改成js的window.location='index.php'

session_start(),header()前不能有任何的输出,包括空格
beauty9235 2005-12-21
  • 打赏
  • 举报
回复
好,我己调试了,
header之前不能有require_once或include之类的
这个说法是错误的,我调试了前后都可以,但必须在前面加上这一句
ob_start();
至于为什么要加,四楼说是缓存,不太理解,但加上就对了,少了不行
谢谢楼上的各位朋友
现在header();和session_start();均可以用了
Fibona 2005-12-20
  • 打赏
  • 举报
回复
header函数之前不能任务输出信息的
maplexm 2005-12-20
  • 打赏
  • 举报
回复
前面加一句ob_start();缓存
SuperBJack 2005-12-20
  • 打赏
  • 举报
回复
如果上面所说的都没问题,把原代码复制出来到TXT文本里。另存一份新的替换掉,就可以了,我也经常遇到这样的问题。是在复制另一模板原时,由于原来的编码和新模块的编码不同而引起的。
zhangli 2005-12-20
  • 打赏
  • 举报
回复
header之前不能有require_once或include之类的
zhangli 2005-12-20
  • 打赏
  • 举报
回复
session.save_path前面去掉;号,后面再设置一下路径即可!
lostgdi731 2005-12-20
  • 打赏
  • 举报
回复
这两个函数必须在所有输出之前执行的。

21,886

社区成员

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

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