错误 - php提示「headers already sent by」是怎么回事?
错误提示:
SAE_Warning: Cannot modify header information - headers already sent by (output started at /data1/www/htdocs/345/leank/1/bbs/login.php:15) in bbs/login.php on line 9
SAE_Warning: Cannot modify header information - headers already sent by (output started at /data1/www/htdocs/345/leank/1/bbs/login.php:15) in bbs/login.php on line 10
SAE_Warning: Cannot modify header information - headers already sent by (output started at /data1/www/htdocs/345/leank/1/bbs/login.php:15) in bbs/login.php on line 28
SAE_Warning: Cannot modify header information - headers already sent by (output started at /data1/www/htdocs/345/leank/1/bbs/login.php:15) in bbs/login.php on line 29
大致的代码:
<?php /* * 未完成内容 : 添加判断的url中log?= "" 的if语句,来判断用户是登陆还是退出 *添加一个判断是否已经登陆的if语句 * */ include("conn.php"); function clearcookies(){ setCookie('username','',time()-3600); setCookie('logset','',time()-3600); } ?> <?php if ($_POST['loginsubmit']) //检查是否提交 { clearcookies(); $sql = "SELECT * FROM user WHERE username = '$_POST[username]'"; $query = mysql_query($sql); $userinfo = mysql_fetch_array($query); if ($_POST[password] != "" & $_POST[username] != "") //检查用户名密码是否填写 { if ($userinfo['password'] == $_POST['password'] ) //在SQL中检查用户名密码是否正确 { $username = $_POST[username]; setcookie('username','$username',time()+31536000,'/'); setcookie('logset','ok',time()+31536000,'/'); echo "<meta http-equiv=refresh content=0;url=index.php?foo=$_POST[username]>"; } else { echo "登录失败!"; echo "请检查您的用户名或密码是否都填写正确"; } } else { echo "登录失败!"; echo "请检查您的用户名或密码是否为空"; } } ?>
处错误的大致是这个位置:
setcookie('username','$username',time()+31536000,'/');
setcookie('logset','ok',time()+31536000,'/');
回复内容:
错误提示:
SAE_Warning: Cannot modify header information - headers already sent by (output started at /data1/www/htdocs/345/leank/1/bbs/login.php:15) in bbs/login.php on line 9
SAE_Warning: Cannot modify header information - headers already sent by (output started at /data1/www/htdocs/345/leank/1/bbs/login.php:15) in bbs/login.php on line 10
SAE_Warning: Cannot modify header information - headers already sent by (output started at /data1/www/htdocs/345/leank/1/bbs/login.php:15) in bbs/login.php on line 28
SAE_Warning: Cannot modify header information - headers already sent by (output started at /data1/www/htdocs/345/leank/1/bbs/login.php:15) in bbs/login.php on line 29
大致的代码:
<?php /* * 未完成内容 : 添加判断的url中log?= "" 的if语句,来判断用户是登陆还是退出 *添加一个判断是否已经登陆的if语句 * */ include("conn.php"); function clearcookies(){ setCookie('username','',time()-3600); setCookie('logset','',time()-3600); } ?> <?php if ($_POST['loginsubmit']) //检查是否提交 { clearcookies(); $sql = "SELECT * FROM user WHERE username = '$_POST[username]'"; $query = mysql_query($sql); $userinfo = mysql_fetch_array($query); if ($_POST[password] != "" & $_POST[username] != "") //检查用户名密码是否填写 { if ($userinfo['password'] == $_POST['password'] ) //在SQL中检查用户名密码是否正确 { $username = $_POST[username]; setcookie('username','$username',time()+31536000,'/'); setcookie('logset','ok',time()+31536000,'/'); echo "<meta http-equiv=refresh content=0;url=index.php?foo=$_POST[username]>"; } else { echo "登录失败!"; echo "请检查您的用户名或密码是否都填写正确"; } } else { echo "登录失败!"; echo "请检查您的用户名或密码是否为空"; } } ?>
处错误的大致是这个位置:
setcookie('username','$username',time()+31536000,'/');
setcookie('logset','ok',time()+31536000,'/');
因为在setCookie之前多输出了东西造成的,看代码似乎是输出了空格,把中间的
?> <?php
去掉应该就可以了
亲爱的.记得每次写完程序后把文件保存成UTF-8 无BOM格式哦.否则就容易出现这样的错误的说~

热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章

热工具

记事本++7.3.1
好用且免费的代码编辑器

SublimeText3汉化版
中文版,非常好用

禅工作室 13.0.1
功能强大的PHP集成开发环境

Dreamweaver CS6
视觉化网页开发工具

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)

PHP 8.4 带来了多项新功能、安全性改进和性能改进,同时弃用和删除了大量功能。 本指南介绍了如何在 Ubuntu、Debian 或其衍生版本上安装 PHP 8.4 或升级到 PHP 8.4

CakePHP 是 PHP 的开源框架。它的目的是使应用程序的开发、部署和维护变得更加容易。 CakePHP 基于类似 MVC 的架构,功能强大且易于掌握。模型、视图和控制器 gu

Visual Studio Code,也称为 VS Code,是一个免费的源代码编辑器 - 或集成开发环境 (IDE) - 可用于所有主要操作系统。 VS Code 拥有针对多种编程语言的大量扩展,可以轻松编写
