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 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题