duanlie7447 2011-12-10 06:05
浏览 39
已采纳

为什么我会收到“无法修改标头信息”和“未定义索引”错误? [重复]

This question already has an answer here:

I have a small php script thats working fine on server but not locally, I tried a lot but can't seem to get rid of these errors and login:

Notice: Undefined index: page in /Users/myusername/Work/www/sabaqk/index.php on line 4

Notice: Undefined index: page in /Users/myusername/Work/www/sabaqk/class/account.class.php on line 26

Warning: Cannot modify header information - headers already sent by (output started at /Users/myusername/Work/www/sabaqk/index.php:4) in /Users/myusername/Work/www/sabaqk/class/account.class.php on line 68

Warning: Cannot modify header information - headers already sent by (output started at /Users/myusername/Work/www/sabaqk/index.php:4) in /Users/myusername/Work/www/sabaqk/class/account.class.php on line 69

Warning: Cannot modify header information - headers already sent by (output started at /Users/myusername/Work/www/sabaqk/index.php:4) in /Users/myusername/Work/www/sabaqk/class/account.class.php on line 70

Warning: Cannot modify header information - headers already sent by (output started at /Users/myusername/Work/www/sabaqk/index.php:4) in /Users/myusername/Work/www/sabaqk/class/account.class.php on line 71

Warning: Cannot modify header information - headers already sent by (output started at /Users/myusername/Work/www/sabaqk/index.php:4) in /Users/myusername/Work/www/sabaqk/class/account.class.php on line 72

I'd really appreciate any help. Thanks!

</div>
  • 写回答

3条回答 默认 最新

  • dongyi2006 2011-12-10 06:21
    关注

    As I stated in comments, Your web server probably has notices and warnings disabled in error reporting and your local host does not. Since your local host has notices enabled, those notice errors are getting printed out near the beginning of your script, which is messing up the rest. When you attempt to set your sessions/cookies (whatever you're using), PHP is unable to do so because content (your errors) has already been sent and the headers along with it, so cookies can't be set anymore.

    Do not just disable error reporting in your PHP script because 1) you won't fix the underlying issue and 2) those errors will still get sent to your Apache error log and the log will become a massive text file of worthless information.

    This is a very simple issue to fix. Just check if your keys exist before attempting to use them, either using array_key_exists() if it's an array, or even simpler, just using isset(). This will get rid of your notice errors and ultimately eliminate your login problem.

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

报告相同问题?

悬赏问题

  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序