Viewed   79 times

I am testing a website online.

Right now, the errors are not being displayed (but I know they exist).

I have access to only the .htaccess file.

How do I make all errors to display using my .htaccess file?


I added these lines to my .htaccess file:

php_flag display_startup_errors on
php_flag display_errors on
php_flag html_errors on

And the pages now display:

Internal server error

 Answers

4

.htaccess:

php_flag display_startup_errors on
php_flag display_errors on
php_flag html_errors on
php_flag  log_errors on
php_value error_log  /home/path/public_html/domain/PHP_errors.log
Tuesday, September 27, 2022
3

You should first test the existence of a file by file_exists().

try
{
  $fileName = 'uploads/Team/img/'.$team_id.'.png';

  if ( !file_exists($fileName) ) {
    throw new Exception('File not found.');
  }

  $fp = fopen($fileName, "rb");
  if ( !$fp ) {
    throw new Exception('File open failed.');
  }  
  $str = stream_get_contents($fp);
  fclose($fp);

  // send success JSON

} catch ( Exception $e ) {
  // send error message if you can
} 

or simple solution without exceptions:

$fileName = 'uploads/Team/img/'.$team_id.'.png';
if ( file_exists($fileName) && ($fp = fopen($fileName, "rb"))!==false ) {

  $str = stream_get_contents($fp);
  fclose($fp);

  // send success JSON    
}
else
{
  // send error message if you can  
}
Friday, September 30, 2022
5

I think you'd better use a .htaccess with the RewriteEngine like this :

RewriteEngine On
RewriteBase /directory/to/dynamic_image
RewriteRule ^logo.png$ logo.php

Or for all .php files :

RewriteEngine On
RewriteBase /directory/to/dynamic_image
RewriteRule ^(.+).png$ $1.php
Saturday, November 12, 2022
 
jason_b
 
3

Please try to do the following:

In .htaccess

    # supress php errors
    php_flag display_startup_errors off
    php_flag display_errors off
    php_value docref_root 0
    php_value docref_ext 0


    # enable PHP error logging
    php_flag  log_errors on
    php_value error_log  /correct_path_to_your_website/error_modes/PHP_errors.log


    # general directive for setting php error level
    php_value error_reporting -1

In php file

Instead of intentional mistake in you wrote in your php file you can try doing something like:

    <?

    echo $_SERVER['DOCUMENT_ROOT']; // this will enable you to see 
                                    // the correct path to your website dir 
                                    // which should be written in .htaccess 
                                    // instead of correct_path_to_your_website
                                    // (check it just in case)

    $foo = $bar['nope'];// this should generate notice 

    call_undefined(); // this should generate fatal error


    ?>

Worked good with me)

Hope it'll help.

Wednesday, September 7, 2022
1

Try this code in root .htaccess:

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule !^public /index.php [L,NC]
Tuesday, September 6, 2022
 
andrii
 
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :