What could this error be? - php

I have upgraded PHP from 5.4 to 5.6 on one of our local servers, and now I have a php file, which when I try to open from the browser, it only results in a blank white screen.
The error reporting in php.ini is set to on, and I've also told at the beginning of the file to report all errors, yet the output is still blank. When I checked the error_log, it is empty. If I delete the whole content of the .php file, and replace it with a simple echo, everything works perfectly.
How could I debug this error?

Problem : Your error_reporting function may be off in your php.ini file.
Solution :
Sometimes by default in php.ini the display error function is off or allowed to show limited errors.
DISPLAY ERROR'S IN YOUR PHP FILE :
So to enable displaying errors in your php file,You will need to add one of the following statements at the begining of your php file just right after your <?php starting tag.
Note : By using any one of these statements,your php file will show every possible error.!
ini_set('display_startup_errors', 1);
ini_set('display_errors', 1);
error_reporting(-1);
Reference Links :
http://php.net/manual/en/errorfunc.configuration.php#ini.display-errors
http://php.net/manual/en/errorfunc.configuration.php#ini.display-startup-errors
http://php.net/manual/en/function.error-reporting.php
#Credit Goes To #brslv

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);

PHP errors not being displayed although they are "on" in the php.ini file

I am on OpenSUSE, I've installed PHP, when I test a simple PHP code, it works, but once I'm trying to display a PHP code that has errors, I get the following error :
The localhost page isn’t working
localhost is currently unable to handle this request.
HTTP ERROR 500
I have changed the value of display_errors to on in the php.ini file, I have also tried all solutions I could find but I still do get that message instead of the actual errors in my PHP file.
I have also added the following lines on the beginning of my PHP file but it didn't solve the problem :
ini_set('display_errors', 1);
error_reporting(~0);

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.

how to display php error message on web page in firefox?

Here is my simple codes file in /var/www/read.php :
error_reporting(E_ALL);
<?php
echo hello"
?>
I ran across the error reporting when to run `php /var/www/read.php ' on debian console.
PHP Parse error: syntax error, unexpected '"', expecting ',' or ';' in /var/www/read.php on line 3
But there is no error reporting in web page when to input 127.0.0.1/read.php in firefox.
I have set the values in php.ini as following:
error_reporting = E_ALL & ~E_NOTICE
display_errors = On
It is no use for me to restart apache2 with command :
service apache2 restart
Here is my phpinfo message.
It is no use to add two lines in my read.php file,no error message reported in my firefox.How can i fix it?My system is debian7+php .
<?php
ini_set('display_errors', 1);
error_reporting(E_ALL);
echo hello"
?>
find / -name 'php.ini'
/etc/php5/apache2/php.ini
/etc/php5/cli/php.ini
The problem solved according to
PHP doesn't show any kind of errors
First, the error_reporting() function should be moved inside the <?php ?> tags.
There are usually two php.ini files in a typical setup (One used by the webserver, other one used by the command line).
On a unix distribution, it is usually located somewhere below the /etc/php folder, like that for example /etc/php/apache2/php.ini.
To be sure what configuration file is loaded for PHP by the webserver, do a simple phpinfo(); in a webpage and just search for configuration file.
If you modify the one used by your websever, make sure to restart Apache afterwards, so it loads the new configuration.
If you want to enforce programmatically setting, you can use the ini_set function.
In your case, if you want to see any error on the page.
<?php
ini_set('display_errors', 1);
error_reporting(E_ALL);
foobar();
Update :
Adding ini_set('display_errors', 1); won't do anything if there is a syntax error in the page, because the syntax error is thrown before the execution of the script. Try to create another type of error, e.g. call an unknown function instead, and you should see it.
Use error_reporting(1); or error_reporting(TRUE); and make sure no where you have disabled anything pertaining to error reporting
add this code in your php file
// Report all PHP errors
error_reporting(-1);
//To show errors
ini_set('display_errors', 1);
error_reporting(E_ALL);
//To hide error
ini_set('display_errors', 0);
You also set this is in a common php file or in working file..
You should see which php.ini is read by Apache. It is common for console to use a different php.ini than Apache.
You can phpinfo() and see which configuration file is being read by Apache.
However, at the beginning of the read.php file add the following line:
init_set("display_errors", 1);
PHP has a nasty habit of giving the white screen of mystery when the error is syntax related. To get around this you can use the include function:
<?php
ini_set('display_errors',1);
error_reporting(E_ALL);
include "/var/www/read.php";
?>
Now the syntax error is no longer in the first page and PHP can "compile" it will give you an error message about the broken page.
There are a couple of issues with the first code sample which should look like this:
<?php
error_reporting(E_ALL);
echo "hello";
?>
First error reporting directives like all PHP code needs to be inside the PHP code tags. This should result in the code simply ending up on the page in Firefox which is not what you want.
Second echo acts on a string which should start and end with a quote mark. This is a syntax error and at the heart of the no error message problem.
Third all line must end with a semi colon (with the exception of a few block level commands). If in doubt... This is actually not your problem and you code will run without it as long as the code section terminates with a ?> as PHP will assume ; for you. However get intot he habit of putting you ; in place every time and you will not be tripped up by it later.
Now assuming that you are not on a host running in safe mode then you can turn on error reporting at the ini level in your code too
<?php
ini_set('display_errors',1);
error_reporting(E_ALL);
echo "hello world";
unknownfunction() // this will throw errors
?>
Judging by the fact that you have full control of the system I would say that you should know if you put safemode on. Also I see that you tried the above ini directive to no available (this is due to the syntax issue that I explained at the start of the answer).
Here is some further reading that might be of interest:
http://www.w3schools.com/php/func_error_reporting.asp
http://www.w3schools.com/php/php_ref_error.asp
http://php.net/manual/en/function.error-reporting.php
How to get useful error messages in PHP?

PHP does not display error messages

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');

Categories