我有一个小的PHP脚本,它在服务器上工作正常但不在本地,我尝试了很多,但似乎无法摆脱这些错误并登录:
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
我真的很感激任何帮助。谢谢!
答案 0 :(得分:1)
这种情况正在发生,因为您的服务器上必须关闭error_display
,而本地系统上则为“ON”。
如果您真的想以编程方式解决这些问题,请使用isset
条件检查错误日志中未定义的所有变量。
答案 1 :(得分:1)
正如我在评论中所述,Your web server probably has notices and warnings disabled in error reporting and your local host does not.
由于您的本地主机已启用通知,因此这些通知错误将在脚本开头附近打印出来,这会弄乱其余部分。当您尝试设置会话/ cookie(无论您使用的是什么)时,PHP无法执行此操作,因为内容(您的错误)已经发送并且标题随之发送,因此无法再设置cookie。 / p>
不要只是在PHP脚本中禁用错误报告,因为1)您将无法修复基础问题,2)这些错误仍将发送到您的Apache错误日志,日志将变为一个无价值信息的大量文本文件。
这是一个非常简单的问题。只需在尝试使用它们之前检查您的密钥是否存在,如果它是一个数组,使用array_key_exists()
,或者使用isset()
更简单。这将消除您的通知错误,并最终消除您的登录问题。
答案 2 :(得分:-1)
您可以包含以下两行来关闭警告和通知:
error_reporting(0);
ini_set('display_errors', false);