Domanda

So basically I have tried to setup an error reporting system that logs any PHP, HTML or any other error into a text file called 'errors.txt' located in a specific directory. However, the file is not being created.

Here is the code:

ini_set('error_reporting', E_ALL);
error_reporting(E_ALL);
ini_set('log_errors',TRUE);
ini_set('error_log','/xampp/xampp-portable-win32-1.8.3-2-VC11/xampp/htdocs/EstateAgent/logs/errors.txt');
ini_set('display_errors',FALSE);

The errors are still be displayed to the user and they error log isn't being created inside of the directory specified.

I have also tried changing the standard values in my 'php.ini' file as suggested on other websites and I have still had no luck.

Any help would be greatly appreciated!

Thanks :)

È stato utile?

Soluzione

For anyone who has similar problem - make sure you don't have any other error_reporting and ini_set in other files you use in your project. In those cases it may seem that error reporting is not working properly but in fact it this.

Try to change:

ini_set('log_errors',TRUE);

into

ini_set('log_errors','1');

and

ini_set('display_errors',FALSE);

into

ini_set('display_errors','0');

If it doesn't help, add at the very top beginning of your file:

<?php
    error_reporting(0);
    ini_set('display_errors','0');
    echo $testVariable;
    echo "Just testing"; 
?>

and check if any warning about this variable is displayed before "Just testing".

Now change above code into:

<?php
    error_reporting(E_ALL);
    ini_set('display_errors','1');
    echo $testVariable;
    echo "Just testing"; 
?>

and check if any warning about this variable id displayed before "Just testing".

As above 2 sample codes works as expacted, it's likely that those settings are change in other php files of user or php libraries used by user. You should scan your code and libraries code do track where changes are made and try to solve this issue either removing your code changing your desired reporting or commenting / setting properly (if there is such possibility in constructor or method) reporting in external library

Altri suggerimenti

You need to provide a fullpath for the 'error_log' property:

<?php
ini_set('error_log', 'c:/xampp/logs/php_error.log');
?>

You need to make sure that the following folder exists and is "writable": c:/xampp/logs/

If you're using Linux, then the fullpath will look like this: /xampp/logs/php_error.log

Also, use the following:

<?php
ini_set('display_errors', '1');
error_reporting(E_ALL);
ini_set('log_errors', '1');
?>
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top