dongtuo3530 2013-06-10 06:21
浏览 26
已采纳

标头已发送错误 - cookies [重复]

This question already has an answer here:

<?php
$user = mysql_real_escape_string($_POST['login']);
$password = mysql_real_escape_string(sha1($_POST['password']));
$query = mysql_query("SELECT * FROM  `users` WHERE name =  '$user' AND pass =  '$password' AND privileges = 'superuser'");
$num_rows = mysql_num_rows($query);

if($num_rows == '1') {
$expire = time()*60*60*60*60;
setcookie("user","$user",$expire);
$_SESSION['user'] = $user;
include '/views/admin/admin.php';
}
else {
echo "Username and Password are incorrect! (Maybe you don't have permission!)";
}
?>

It says

Warning: Cannot modify header information - headers already sent by (output started at Z:\home\test1.ru\www\views\admin\validate.php:1) in Z:\home\test1.ru\www\views\admin\validate.php on line 9

line 9 is - setcookie("user","$user",$expire);

</div>
  • 写回答

4条回答 默认 最新

  • dtp19819 2013-06-10 06:25
    关注

    cookies in HTTP will be transferred using the headers. setcookie() therefore is just a wrapper around header() and cannot being used if there were already output in that script.

    I guess that the output is an error message triggered by the mysql_* functions or whitespace|content before the opening <?php tag

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向