Welcome Guest, Not a member yet? Register   Sign In
CI4 Whoops additions if and only if LOCALHOST
#1

(This post was last modified: 09-25-2019, 11:07 PM by John_Betong.)

I use Ubuntu 19.04 and have added these lines in index.php to clear the LOCALHOST log file:

file: index.php
PHP Code:
# MAYBE EMPTY TRASH IF AND ONLY IF LOCALHOST
  if( 'localhost'===$_SERVER['SERVER_NAME'] ) :
    $ok = @unlink('../writable/logs/log-' .date('Y-m-d') .'.php');
    $ok = @array_map('unlink'glob("../writable/debugbar/*.json"));
  endif; 

And also modified the following file:
  /app/Views/errors/html/production.php

PHP Code:
<?php // DECLARE(STRICT_TYPES=1);


?><!doctype html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="robots" content="noindex">

    <title>Whoops!</title>

    <style type="text/css">
        <?= preg_replace('#[\r\n\t ]+#'' 'file_get_contents(__DIR__ DIRECTORY_SEPARATOR 'debug.css')) ?>
        .whoops {
            background-color: #ddffff; color: #000;
            border: solid 1px #888;
            font-size: small;
            margin:0 auto; padding: 0.42em;
            width:88%; max-width:88em;
        }
        .ooo {margin: 0 0 2em 0; padding: 0;}
    </style>
</head>
<body>

    <div class="container text-center">
        <h1 class="XXXheadline"> Whoops! </h1>

        <p class="lead">We seem to have hit a snag. Please try again later...</p>
    </div>

    <?php 
        
# better if LOCALHOST defined in 'index.php'
        
if( 'localhost'===$_SERVER['SERVER_NAME'] ) :
            
$today 'logs/log-' .date('Y-m-d') .'.php';
            
$today highlight_file(WRITEPATH .$todayTRUE);

            echo 
'<div class="whoops">'
                        
.    '<dl>'
                        
.    '<dt><b> The last error which must be fixed </b></dt>'
                      .        '<dd><br>' .$today .'</dd>'
                        
.'</dl>'
                    
'</div>'
                    
;    
    endif;
    
?>    
    </div>    
</body>
</html> 

Output:
[Image: Whoops.png]I use Ubuntu 19.04 and have modified the following file for a better Whoops:
Reply


Messages In This Thread
CI4 Whoops additions if and only if LOCALHOST - by John_Betong - 09-25-2019, 10:39 PM



Theme © iAndrew 2016 - Forum software by © MyBB