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 :)
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
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');
?>
Related
I have a file called web.php inside that file I store code for define base URL address, assets folder.... File have next code:
<?php
define('BASE', 'https://example.com/');
define('ASSETS', BASE . 'assets/');
?>
So if we call function from above <?php echo BASE; ?>home.php i get error that says, check above.
All works fine but get an error that says, you need to change `BASE` it will throw an error in featured PHP Versions. I try to define different names, but same error. Can someone explain to me, how I can resolve this issue?
Im trying to repeat your Error
And as i see there no Errors at all
My PHP version is 7.4.3
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
define('BASE', 'https://example.com/');
define('ASSETS', BASE . 'assets/');
echo BASE;
echo "No errors";
Is it really php throw or may by it comes from your Framework?
This is what I tell php to do:
<?php
error_reporting(E_ALL);
ini_set('display_errors', '0');
ini_set('log_errors', 1);
ini_set('error_log', 'errors.log');
ini_set('error_append_string', 'APP');
ini_set('error_prepend_string', 'PRE');
?>
Hoping that I would get all errors reported in one file, with "PRE" before the message and "APP" after the message. (My goal is to make PRE and APP into /n /r or something...)
But my error reporting log looks like this:
[14-May-2013 00:16:26] PHP Notice: Undefined variable:
nonexistentvariable in /home/www/dir/index.php on line 14[14-May-2013
00:16:28] PHP Notice: Undefined variable: nonexistentvariable in
/home/www/dir/index.php on line 14
No PRE, no APP...
How do I get it in there, so that my error reporting file will have each error on a newline, rather than a loooong string of errors that's not helpful to me?
EDIT:
So I noticed that with ini_set('display_errors', '1'); the "APP" and "PRE" strings are displayed on the page, in the error message.
That means I really need to find out where I can change the format for how php logs the errors. For example this whole timestamp thing - where is that specified?
EDIT:
It is not possible to change the way php logs errors, you have to make your own error handler.
ANSWER:
To truly achieve what I was going to, I asked a different question (to be more precise).
How to change the way PHP writes errors in the error log file?
As the documentation says nothing to that, I have tested your example. I realized that error_append/prepend_string only works for displayed but not logged errors
My goal is to make PRE and APP into /n /r or something...
You should use a regex for that. Should be possible, as every log messages starts with nearly same prefix. Will prepare one....
check phpinfo(); after ini_sets
Trying to figure out why a Wordpress site I moved is doing white screen of death.
Trying to turn on error dumping - but it isn't working. Absolutely nothing is showing up.
Here's sample code:
<?php
ini_set('display_errors', 1);
ini_set('log_errors', 1);
ini_set('error_log', dirname(__FILE__) . '/error_log.txt');
error_reporting(E_ALL);
$con = mysql_connect('localhost', 'groupasa', 'groupasa');
$selected = mysql_select_db("groupasa",$con)
Echo "Test";
?>
for a fatal error you can turn on errors in php code you have to turn them on in apache or htaccess level. You could also go and look in the error log for the errors.
Right click and check the source of your page, sometimes the html doesn't show the error but it's actually in the code.
Not sure if this is the case but hope it helps.
Try putting the Echo statement at the very top of the page and then an exit; if the echo displays then your PHP compiler is working fine and you know that the issue is with the code on the page.
next, add the missing semicolon at the end of mysql_select_db line
you could also check your PHP error logs.
Most times you can solve the 'white screen' by going into the database and using the following query to forcibly 'deactivate' all active plugins.
UPDATE wp_options SET option_value = '' WHERE option_name = 'active_plugins';
The core of WP is pretty solid, but it's the plugins and garbage that really mucks everything up.
I've been working with PHP for a while, but fairly new to Smarty.
I'm working with Prestashop and I've noticed Smarty seems to eat up all PHP errors - when there's an error in the PHP code, the .tpl file just outputs a blank page. I've been trying but I can't get Smarty to display whatever the PHP code outputs, even if there's an error.
PHP error reporting is set to show errors.
So, for instance, let's say this is the example.php file:
<?php
//included classes etc go here, irrelevant for this issue
error_reporting(E_ALL ^ E_NOTICE);
echo obvious wrong syntax"
?>
This file is connected to example.tpl which fits the output in a template block.
Obviously, it should throw an error. How do I make Smarty actually display that error?
To activate debug mode, go to config/config.inc.php
Find the following lines and chage off to on for the first one and set to true the second
/* Debug only */
#ini_set('display_errors', 'on');
define('_PS_DEBUG_SQL_', true);
This will display PHP and SQL errors (this would probably be enough for you to resolve "blank page").
There is also a blog post on prestashop site about p() and d() methods and how to track exceptions
To activate templates debug in Prestashop version older than 1.5,go to config/smarty.config.inc.php
Find the following line and set it to true
$smarty->debugging = true;
When you refresh your page, themes/debug.tpl should be rendered.
To activate templates debug in Prestashop 1.5+ you can enable Smarty debugging via Admin panel
Preferences > Performance > Smarty
and set Always open console but console will be opened for everyone ( not good for live site :) )
or set Open console with URL parameter (SMARTY_DEBUG) and add ?SMARTY_DEBUG to the end of your URL to see console
Hope this helps.
I've seen #Sergei Guk's answer and off-course, it's a pretty good answer. However, prestashop has since released version 1.6.
So if you want to show all the errors in prestashop v 1.6.0.6, you just need to go config/defines.inc.php
Replace define('_PS_MODE_DEV_', false); with define('_PS_MODE_DEV_', true);
What it actually does is set a constant and in the next line it checks if "_PS_MODE_DEV_" is true then it will show all kinds of errors in prestashop
if (_PS_MODE_DEV_)
{
#ini_set('display_errors', 'on');
#error_reporting(E_ALL | E_STRICT);
define('_PS_DEBUG_SQL_', true);
}
else
{
#ini_set('display_errors', 'off');
define('_PS_DEBUG_SQL_', false);
}
I have tested it and it works fine.
Set the $error_reporting variable.
See http://www.smarty.net/docsv2/en/variable.error.reporting.tpl
I have a weird problem, I am using print_r($obj) in Joomla YOOtheme ZOO extension and it returns a blank page. it just act as die() !
it should output the object but it does not.
Please note that print_r() is working fine with some other objects and variables.
I am using XAMPP on Windows.
Any help?
Upon executing print_r() and var_dump(), the page is just blank, no error, view source shows:
<html>
<head></head>
<body></body>
</html>
Error reporting is turned on.
It is posible that $obj is too big to load, and grabs a lot of memory after which the script stops to work.
Thanks
Is error reporting turned on?
If not add to your code:
ini_set("display_errors", "1");
If it's outputting nothing, $obj contains nothing. Try var_dump() instead. Also, make sure you're seeing all errors that PHP is producing:
ini_set('display_errors', 1);
error_reporting(-1);