doupi1532 2013-08-11 02:26
浏览 27

如何在html标签中包装php错误?

I have a site that has an absolutely positioned navigation bar that sits at the top of the window, so that when I scroll down the page, the rest of the content goes underneath it.

The site is currently in its "testing" phase and there is the occasional php error that appears on the page. Unfortunately, it appears at the top of the code and is therefore showing at the top of the window which is visually covered by the absolutely positioned navigation bar. I myself could use the inspector to hide the navigation bar to see what the error message reads that is underneath the nav bar, but the other users I have testing the site do not know how to do that.

I would like to wrap the php errors that are output in custom html tags which I can then give a higher z-index to so it appears above the navigation bar. Then, the users can report to me what the exact php error is that is displayed to them.

How can I wrap my php errors in html tags?

  • 写回答

1条回答 默认 最新

  • douzhao4071 2013-08-24 23:09
    关注

    You can create your own error handler as such: http://php.net/manual/en/function.set-error-handler.php

    This will let you control how the error is outputted. In your case:

    function myErrorHandler($errno, $errstr, $errfile, $errline) {
        if (!(error_reporting() & $errno)) {
            // This error code is not included in error_reporting
            return;
        } 
    
        echo "<p class="error">ERROR: [$errno] $errstr <br />
    ";
        echo "  Fatal error on line $errline in file $errfile </p>";
    }
    

    Should work?

    Also, if you want to log the fatal errors, use this;

    function shutdownFunction() { 
        $error = error_get_last(); 
        if ($error['type'] == 1) { 
            // fatal error logging goes here
        } 
    }
    register_shutdown_function('shutdownFunction'); 
    
    评论

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大