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

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?

Related

What could this error be?

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

I've turned display_errors to On but I don't see any errors on the webpages

I'm trying to see what error PHP is producing. So I've changed the value of dispaly_errors to ON in the etc/php5/apache2/php.ini file.
The file doesn't display anything and I don't see any error on the webpages.
Am I missing any thing?
First, you have to make sure that this is your correct ini file. Usually the file you have used is the correct one. If not sure, you can create a simple PHP program to call the phpinfo() function and check this out.
Next, you have to restart Apache. Without a restart your settings don't take effect.
Another thing... This file can be a little misleading because there are so many comments in it. The actual line to change is way down. On my setup (LAMP/Ubuntu) the setting is on line 538.
Open php.ini file from your php folder, remove semicolon from all error reporting like
;error_reporting=E_ALL & ~E_DEPRECATED & ~E_STRICT, ;display_errors=On etc, at last, restart your server, you will find all error messages.
Another way for showing error, you can write these codes in your script -
echo '<pre>';
error_reporting(E_ALL);
ini_set('display_errors', 1);
In addition to enabling display_errors, you may also need to set the error reporting level. if you are expecting errors with a script that is redirecting, be sure to turn off the redirection or you may never see them.

php isn't giving any error in output

I have apache2 installed on my PC.
And php5 and all the stuffs.
The php is also running fine. I checked commands INSERT INTO myTable etc and it's working fine.
I've phpMyAdmin installed and it's also working fine.
The problem is that I'm not getting any error when there is actually error.
for e.g.
PHP :
<?php
<?php
$umair = 1
echo $umair;
echo 'asdf';
?>
This code isn't outputting anything. As you can see there is error of semicolon here and the PHP must show some error.
And if I put the semicolon then the PHP runs as usual and get the output 1asdf
Set your php.ini settings to display errors :
- error_reporting to E_ALL
- display_errors to on
(those are developement environment settings of course ; more about error_reporting levels here)
You can find your php.ini location using phpinfo() in a PHP script.
EDIT In case it isn't that, try to execute a valid script, and tell us if it runs correctly. If it doesn't, it probably means that your php module installation failed somehow.
EDIT 2 Restarting Apache will be necessary after editing such parameters.
You can try to show the errors for the current file that you're working on right now by adding
error_reporting(E_ALL);
and try to check this
The problem is that the missing ";" is a parser error - and parsing is done before execution.
PHP will simply not even start executing an invalid script - so you don't see anything.
Try to include this script in another script and run that - then you will get a clear error-msg!
Here's more on that topic and also my script to do this: 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');

What to do when no errors and error-reporting enabled?

Im lost here, closed few files and clicked yes on save all and now page wont load and error_reporting(1); its in all documents... No erors given
If your error isn't a syntax error, you can manually debug by placing die('test'); in various areas of your code to see if that portion executes.
You also need to turn on the display of errors, so at the top of your file add:
error_reporting(E_ALL);
ini_set("display_errors", 1);
Turn on error_reporting and display_errors in your php.ini file. If you have a syntax errror in the script, most likely the script's being killed long before execution could ever reach in the in-script ini_set/error_reporting overrides.
You might want to check the server's error log, as fatal errors generally get sent there if error reporting/display is turned off.

Categories