PHP does not display error messages - php

I installed XAMPP 1.7.4 (with PHP 5.3.5), the problem is PHP does not display any error messages. E.g. if I connect to MYSQL with mysql_connect() without parameters, PHP will not complain about the required fields.
Why is this?
How can I configure PHP to display errors?

To turn on errors at the script level, include at the top of your script:
ini_set('display_errors', 1);
error_reporting(~0);
Alternatively, if it is not a production site and simply a development / testing site, you can turn on error reporting in php.ini. Search it for these settings:
error_reporting = E_ALL
;error_reporting = E_ERROR
display_errors = On
;display_errors = Off

May be the display error is off
add in .htaccess file of your application.
php_value display_errors on
OR
use this at the top of your php script
ini_set('display_errors',"1");

To show error message on page over browser for php script use following code in top of your php file.
<?php
ini_set('display_errors', 1);
error_reporting(~0);
?>
and there is another way to check php error code if you are linux ubuntu user execute following command on terminal.
NOTE : -10 is the number of message you want to show.

It possibly did override your settings in the php.ini. Check the php.ini for error handling parameters and make sure they're switched on.
Happened to me a few weeks ago, too

You can use following code in your program
error_reporting(E_ALL);
ini_set('display_errors', '1');

Related

Not displaying errors in php

I am debugging some errors in my PHP bus booking site. My issue is that I am not able to display errors. When I googled this issue it shows you can achieve it though php.ini. But unfortunately I haven't find any php.ini file .
Now the error is showing as
This page isn’t working
cableandmedia.com is currently unable to handle this request. HTTP
ERROR 500
On your all-pages/or-a-common-file which-is-included-in-each-file.
On top just after starting <?php add these two lines:-
error_reporting(E_ALL);
ini_set('display_errors',1);
If you have php.ini file then check these two variables:-
display_errors
error_reporting
Now change these variables values to:-
display_errors=ON
error_reporting=E_ALL
Now save the file and restart your server(important if you are working on localhost).And you have good to go.
Add this line to your php file. To debug
ini_set('display_errors', 1);
error_reporting(E_ALL);

No detailed error messages

I am getting internal server error when calling php script via ajax. I set ini_set("display_errors", 1); error_reporting(E_ALL); but still no details .. what else should I do
inside your php.ini the
display_errors = On
The php.ini file is where base settings for all php on your server, however these can easilybe overridden and alterd any place in the PHP code and affect everything following that change. This happens a in frameworks. A good check is to add the display_errors to you php.ini. If you don't see an error, but one is being logged, insert this at the top of the file causing the error:
ini_set('display_errors', 1);
error_reporting(E_ALL);
If this works then something earlier in your code is disabling error display.

PHP errors not being shown when using error_reporting and ini_set (PHP module in Apache 2.2)

I am trying to use error_reporting() in order to show all errors in my php script
error_reporting(E_ALL);
error_reporting(-1);
ini_set('error_reporting', E_ALL);
However, while php errors are properly logged, none of the functions above show the errors in the page.
I know the error reporting can be properly set in the php.ini file (I know how to that), but I don't understand why it can't be changed on the fly using the standard php functions.
I am suspecting Apache not authorizing to do so (php is installed as a module, config file is in /etc/php5/apache2/php.ini )
Thanks for your help

error_reporting(E_ALL) does not produce an error

This is my PHP script -
<?php
error_reporting(E_ALL);
echo('catch this -> ' ;. $thisdoesnotexist);
?>
Which obviously should show something if it were to be executed.
All I see is an empty page. Why is error_reporting(E_ALL) not working?
<?php
ini_set("display_errors", "1");
error_reporting(E_ALL);
echo('catch this -> ' ;. $thisdoesnotexist);
?>
Does not help either. All I get is an empty page.
I've been to php.ini and set display_errors = On and display_startup_errors = On. Nothing happens.
Your file has a syntax error, so your file was not interpreted, so settings were not changed and you have a blank page.
You can separate your file in two:
File index.php
<?php
ini_set("display_errors", "1");
error_reporting(E_ALL);
include 'error.php';
File error.php
<?
echo('catch this -> ' ;. $thisdoesnotexist);
That error is a parse error. The parser is throwing it while going through the code, trying to understand it. No code is being executed yet in the parsing stage. Because of that it hasn't yet executed the error_reporting line, therefore the error reporting settings aren't changed yet.
You cannot change error reporting settings (or really, do anything) in a file with syntax errors.
In your php.ini file check for display_errors. I think it is off.
<?php
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);
In your php.ini file check for display_errors. If it is off, then make it on as below:
display_errors = On
It should display warnings/notices/errors.
Please read error_reporting int.
You can try to put this in your php.ini:
ini_set("display_errors", "1");
error_reporting(E_ALL);
In php.ini file also you can set error_reporting();.
Turn on display errors in your ini file:
display_errors string
Just do the following:
Check phpinfo();. Check if display_errors is on or off
If it is On, just add error_reporting(E_ALL); in your primary index file.
If it is Off, just add it in your primary index file
ini_set("display_errors", "1"); // This is the instant setup for individual applications
error_reporting(E_ALL);
then check phpinfo();. Check display_errors. Now it is on, which is only for this application
then create any code error for testing and reload the page
Hurray! Now you can see the errors in your console. If the errors are not displaying in your console and the page loading failed with a red alert in network, don't worry.
Check if you have enabled modsecurity and it has any rule checking is written in SecRule for PHP. Remove that secrule or disable the modsecurity for your development period.

How to have PHP display errors? (I've added ini_set and error_reporting, but just gives 500 on errors)

So, I don't really have any errors in my current web page, but I want to be able to see an error when they pop up, instead of the HTTP 500 error page. I googled around a bit and thought adding these two lines would fix everything.
ini_set('display_errors', 'On');
error_reporting(E_ALL);
NOTE: I don't have access to the php.ini file, as I'm using my school account's server.
So I introduced a bug (no semicolon after $buggy) like so at the top of my page:
<?php
ini_set('display_errors', 'On');
error_reporting(E_ALL);
$buggy
$x = 4 + 2;
...
However, I just get a Server error:
"The website encountered an error while retrieving http://mywebpage.com/. It may be down for maintenance or configured incorrectly."
Any ideas?
EDIT:
I've reconfigured my code:
<?php
include_once 'database/errorSettings.php';
?>
<?php
$buggy // whoops
$x = 4 + 2;
...
errorSettings.php is the following:
<?php
ini_set('display_errors', 'On');
error_reporting(E_ALL);
?>
But it still doesn't work... wrong way to reconfigure?
What you have is a parse error. Those are thrown before any code is executed. A PHP file needs to be parsed in its entirety before any code in it can be executed. If there's a parse error in the file where you're setting your error levels, they won't have taken effect by the time the error is thrown.
Either break your files up into smaller parts, like setting the error levels in one file and then includeing another file which contains the actual code (and errors), or set the error levels outside PHP using php.ini or .htaccess directives.
You need to set the error_reporting value in a .htaccess file. Since there is a parse error, it never runs the error_reporting() function in your PHP code.
Try this in a .htaccess file (assuming you can use one):
php_flag display_errors 1
php_value error_reporting 30719
I think 30719 corresponds to E_ALL but I may be wrong.
Edit Update: http://php.net/manual/en/errorfunc.constants.php
int error_reporting ([ int $level ] )
---
32767 E_ALL (integer)
All errors and warnings, as supported, except of level E_STRICT prior to PHP 5.4.0. 32767 in PHP 5.4.x, 30719 in PHP 5.3.x, 6143 in PHP 5.2.x, 2047 previously
Adding to what deceze said above. This is a parse error, so in order to debug a parse error, create a new file in the root named debugSyntax.php. Put this in it:
<?php
/////// SYNTAX ERROR CHECK ////////////
error_reporting(E_ALL);
ini_set('display_errors','On');
//replace "pageToTest.php" with the file path that you want to test.
include('pageToTest.php');
?>
Run the debugSyntax.php page and it will display parse errors from the page that you chose to test.
Just write a following code on top of PHP file:
ini_set('display_errors','on');
Syntax errors is not checked easily in external servers, just runtime errors.
What I do? Just like you, I use
ini_set('display_errors', 'On');
error_reporting(E_ALL);
However, before run I check syntax errors in a PHP file using an online PHP syntax checker.
The best, IMHO is PHP Code Checker
I copy all the source code, paste inside the main box and click the Analyze button.
It is not the most practical method, but the 2 procedures are complementary and it solves the problem completely
I have had this problem when using PHP5.4 and Plesk 11.5
Somehow, the error reporting and display error settings in the Plesk domain configuration page were completely overriding any local settings in .htaccess or the PHP scripts. I have not found a way to prevent this happening, so use the Plesk settings to turn error reporting on and off.
You may have settings in your php.ini that prevents the local site from overriding these settings, perhaps enforced by the control panel used on your server.
To people using Codeigniter (i'm on C3):
The index.php file overwrite php.ini configuration, so on index.php file, line 68:
case 'development':
error_reporting(-1);
ini_set('display_errors', 1);
break;
You can change this option to set what you need. Here's the complete list:
1 E_ERROR
2 E_WARNING
4 E_PARSE
8 E_NOTICE
16 E_CORE_ERROR
32 E_CORE_WARNING
64 E_COMPILE_ERROR
128 E_COMPILE_WARNING
256 E_USER_ERROR
512 E_USER_WARNING
1024 E_USER_NOTICE
6143 E_ALL
2048 E_STRICT
4096 E_RECOVERABLE_ERROR
Hope it helps.

Categories