全球主机交流论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

CeraNetworks网络延迟测速工具IP归属甄别会员请立即修改密码
查看: 562|回复: 7

[疑问] 【PHP问题】Warning: Cannot modify header infor

[复制链接]
发表于 2022-8-2 10:03:15 | 显示全部楼层 |阅读模式
本帖最后由 NoctuG 于 2022-8-2 10:04 编辑

打开页面报错——

  1. Warning: Cannot modify header information - headers already sent by (output started at /users/remy/www/application/header.php:1) in /users/remy/www/application/function.php on line 25
复制代码

第25行内容为

  1. header('Content-Type:text/html;charset=utf-8');
复制代码


请问是那里有问题?
发表于 2022-8-2 10:08:44 来自手机 | 显示全部楼层
不能在已经输出个别字符之后再header,要header必须在所有字符都没输出之前,空格,换行之类的也不行!
发表于 2022-8-2 10:08:53 | 显示全部楼层
放到第一行,就可以了。
  1. <?php
  2. header('Content-Type:text/html;charset=utf-8');
复制代码


当然也可以 注释掉
  1. //header('Content-Type:text/html;charset=utf-8');
复制代码
 楼主| 发表于 2022-8-2 10:09:34 | 显示全部楼层
逸笙 发表于 2022-8-2 10:08
不能在已经输出个别字符之后再header,要header必须在所有字符都没输出之前,空格,换行之类的也不行! ...

谢谢大佬
 楼主| 发表于 2022-8-2 10:10:41 | 显示全部楼层
feixiang 发表于 2022-8-2 10:08
放到第一行,就可以了。

纯PHP小白,谢谢大佬提醒
发表于 2022-8-2 10:36:39 | 显示全部楼层
NoctuG 发表于 2022-8-2 10:10
纯PHP小白,谢谢大佬提醒

我也是小白,刚好遇到并处理过这个问题...
 楼主| 发表于 2022-8-2 21:44:38 | 显示全部楼层
本帖最后由 NoctuG 于 2022-8-2 21:48 编辑
feixiang 发表于 2022-8-2 10:36
我也是小白,刚好遇到并处理过这个问题...


新问题
  1. Warning: Cannot modify header information - headers already sent by (output started at /users/remy/www/application/header.php:1) in /users/remy/www/admin/index.php on line 9

  2. Warning: Cannot modify header information - headers already sent by (output started at /users/remy/www/application/header.php:1) in /users/remy/www/admin/index.php on line 75

  3. Warning: Cannot modify header information - headers already sent by (output started at /users/remy/www/application/header.php:1) in /users/remy/www/admin/index.php on line 81
复制代码

  1. 9行
  2. header("Content-Type: text/html;charset=utf-8");

  3. 75行
  4.             setcookie('auth', $setCOK, time() + 3600 * 24 * 14, '/');

  5. 81行
  6.             header("refresh:2;url=" . $config['domain'] . "");
复制代码

发表于 2022-8-2 22:17:55 来自手机 | 显示全部楼层
你不能手痛就把手移到脑袋上啊。你要解决的是“在header()之前你已经有输出字符”这件事。我说了,不能有可见字符,也不能有空格,连换行都不能有!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|全球主机交流论坛

GMT+8, 2026-5-13 07:38 , Processed in 0.067996 second(s), 8 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表