不显示PHP错误 [英] PHP errors aren't displayed

查看:89
本文介绍了不显示PHP错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 <!DOCTYPE html> 
< html>
< head>
< meta http-equiv =Content-Typecontent =text / html; charset = UTF-8>
< title>< / title>
< / head>
< body>

<?php
ini_set('display_errors',1);
ini_set('log_errors',1);
include_once('../ API / session_management.php');
//检查会话固定:
$ sess = new session_management();
$ sess-> set_session_configurations();
$ sess-> prevent_session_hijacking();
?>
sdfsd
< a href =>< / form>
< form>
< input type =textname =test/>
< / form>
< / body>



问题是,当我运行代码,出现错误。正在打印空白页。没有错误显示。为什么是这样的,我怎样才能启用错误?



这是我得到的输出,并且在将php中的显示错误更改为on并重新启动apache之前: / p>



 <!DOCTYPE html> 
< html>
< head>
< meta http-equiv =Content-Typecontent =text / html; charset = UTF-8>
< title>< / title>
< / head>
< body>


解决方案

您需要的两行是

  ini_set('display_errors','On'); 
error_reporting(E_ALL);

设置 php.ini 文件用于您的开发环境。这将删除项目中的非生产代码,并解决导致您的 ini_set() error_reporting()调用不被执行(感谢 Corbin )。



另一个建议,在任何HTML开始之前(在脚本的顶部)放置你的PHP代码。看起来你正在处理在任何事情被添加到输出缓冲区之前应该完成的会话。


I have this mark up:

<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title></title>
</head>
<body>

    <?php
      ini_set('display_errors', 1); 
        ini_set('log_errors', 1); 
      include_once('../API/session_management.php');
      //Checking session fixation:
      $sess=new session_management();
      $sess->set_session_configurations();
      $sess->prevent_session_hijacking();
    ?>
    sdfsd
    <a href=""></form>
    <form>
        <input type="text" name="test"/>
    </form>
</body>

The problem is that when I run the code, there is an error. A blank page is being printed. No error is displayed. Why is this, and how can I enable errors?

This is the output that I get after and before changing the Display errors to on in php ini and restarting apache:

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title></title>
    </head>
    <body>

解决方案

The two lines you need are

ini_set('display_errors', 'On');
error_reporting(E_ALL);

It's much better to set these in the php.ini file for your development environment. This removes non-production code from your project and solves problems like syntax errors causing your ini_set() and error_reporting() calls not to be executed (thanks Corbin).

Another suggestion, place your PHP code before any HTML starts (right at the top of the script). It looks like you're dealing with sessions which should be done before anything is added to the output buffer.

这篇关于不显示PHP错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆