Turn off php warnings in cPanel - php

Is there any specific way to turn off PHP warnings in cPanel? Or is there a way to disable PHP warnings using code? The reason for this question is following error,
Warning: session_start(): Cannot send session cookie - headers already sent by (output started at /home/fteeloco/public_html/login_process.php:1) in /home/fteeloco/public_html/login_process.php on line 2
The reason for this error is (as I think ) adding white space before the PHP start tag.
Please help.

Move the session_start() in first line of your page. Error will be resolved.
Note: Add it in header file if you you have header (eg: header.php) file separately. Remove from login_process.php

Add session_start() to the start of php pages where you are using Session variables (if not added).

I want to start by saying that: you are wrong! That is not the reason that you see that warning. The reason is that you started the session before, and then you started it again. So look in your code for 2 lines with "session_start()". Even if this is not right, session_start() must be the first line in your script!!!
Now to answer your question!
There are 2 ways to do this:
disable warnings from php.ini
Open PHP.ini file.
In this file search for the phrase “ error_reporting = E_ALL” ,[without inverted commas]
Here replace this with “error_reporting = E_ALL & ~E_NOTICE & ~E_WARNING “
(Show all errors, except for notices and coding standards warnings)
Make sure you change the real enabled part of this , there are certain other examples given in the file.
Restart your PHP + Apache
use the error_reporting() function in PHP like is described in the PHP manual HERE
But I must warn you, nither of this are considered good practice. It is not ok to disable warning, notice or error messages.
Hope this helps! :D

Related

Notice warning from PHP in Symfony uploading file

I have a form that allows upload three files at the same time but just one is required. That works fine, my only problem is the following: if I upload three files I haven't any problem but if I upload one or two files (leaving two or one files empties) I obtain the following notice:
Notice: No file uploaded in Unknown on line 0
As much as empty files. The files are uploaded properly without any other problem, but I want remove that notice... or unless hide it, although I prefer remove it. I tried to hide it using
error_reporting(0);
and
ini_set('display_errors',0);
but neither of two worked...
It is the first time that I have problem, if someone could lead me I'd be very grateful due to that I am stuck with it.
If you are having the same problem as me, check with phpinfo() if you are using a debug version of PHP. If you see that Debug Build has a value of yes, your problem will be fixed if you install a live version of PHP instead of a debug version
The Error itself is caused by running a Debug version of PHP 7, see the bug report. As noted by HPierce because it was a Debug build it overrides the usual PHP settings for error_reporting. However as the Original question is actually about how to hide certain [expected] error messages (Notices), my answer is to this detail specifically.
Kevin, the attempted ways to hide errors you've listed in your question would normally work on non-debug PHP builds. However, it is unwise to ignore the errors, rather than solving them at source. It's also (more) unwise to hide all errors simply due to having expected errors appearing.
As it's only a Notice, you can work around it by setting your error_reporting() value as below:
//report all errors except notices.
error_reporting(E_ALL & ~E_NOTICE);
I would suggest this is far wiser than turning off error reporting entirely which is not recommended. If you want to stop errors being output to browser (as referenced by Tina) you can use display_errors.
Perhaps you may also need to set
ini_set('error_reporting', 0);
depending on your php ini configuration?
Also make sure you set it before carrying out any of the code.

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.

Show Header error on localhost

When I uploaded my site to the server I got these errors.
Warning: Cannot modify header information - headers already sent by (output started at /home/content/j/o/u/jou/html/biggydaddy/wp-config.php:25) in /home/content/j/o/u/jou/html/biggydaddy/wp-login.php on line 12
I understand the reasons behind them, but in my localhost this warning not shown.
How do I display those errors?
1)This error comes when you print any thing before php hreader command
Please check for any echo or print / print_r .. (or may be White Space)
2)
You need to set both error_reporting and display_errors. These can be set in php.ini, in Apache (if you're using PHP as an Apache module) or during run-time, though if you set it during run-time then it won't effect some types of errors, such as parse errors.
Be sure that you have set output_buffering=Off
for showing error on localhost you have to set output_buffering=Off in your php.ini file and then restart your XAMPP .....
Have a look at the file mentioned (/home/content/j/o/u/jou/html/biggydaddy/wp-config.php) and make sure nothing is being output from there. This could be as simple as an extra space before the opening <?php tag.
In my Wordpress config file that line is the DB password. Make sure that you haven't got any characters there like an extra unescaped quote that could cause problems.
Sometimes it's some space characters after the final ?> in a PHP file.
It seems you are using wordpress then set WP_DEBUG constant to true in wp-config.php:
define('WP_DEBUG', true);
Or if for normal php script set:
error_reporting(E_ALL);
ini_set("display_errors", 1);
Hope this will help you.

Suppressing PHP undefined variable messages?

When I developed a website on my localserver it was working fine.
Now that I've uploaded it live I'm getting several notices.
Notice: Undefined index: ... on line 14
I've figured out that it happens because I'm using variables which arn't defined, and would like to go through and fix it. But I need a live version working tonight.
Is it possible to suppress the Notices and have the website act as it does on my localhost while its on my live server?
You've got it twice wrong. On your localhost and on your live server!
Localhost
Always show everything on screen, you want to know about notices too before you go live, as you can see now!
Live server
Never show anything on screen, it makes you vulnerable (it's deadly)
Log everything, also notices! So don't do what the other answers tell you!
You can choose which kind of errors will show up on your site on a global scale through php.ini or through .htaccess for specific folders, or per script by using error_reporting().
Read more on that and which options to set for your specific needs at www.php.net/manual/en/function.error-reporting.php
Also read: http://www.php.net/error-reporting
Look in the file php.ini for a line similar to error_reporting = E_STRICT - Edit it to remove the STRICT bit and put in error_reporting = E_ERROR.
I would recommend that in the near future that you fix those errors anyway.

Warning for header information in my test server but not in local why?

I have my site live in which i echoed few strings for testing, so it displayed me those test strings but along with the warning message
Warning: Cannot modify header
information - headers already sent by
(output started at
/home/companyfolder/public_html/mycart.php:117)
in
/home/companyfolder/public_html/includes/functions/general.php
on line 50
But at the same time i do not get this error any where in my local machine so i want to know is there any difference in display of header information related to servers?
Because of output buffering
And not a single one, who volunteered to share their knowledge about error handling, mentioned a way more likely reason - display_errors turned off, as it on the live site ought to be.
Of course it should be. To
not to scare users with strange messages
not to reveal vital info of your application to possible attacker. nor to supply them with any feedback.
inform a programmer of all errors occurred, by turning log_errors setting on
Thus, on a development site
display_errors = on
log_errors = off
on a live site
display_errors = off
log_errors = on
while error reporting level should remain the same - E_ALL or better
You have the same issue in both places, just different error reporting levels. You can configure this in your php.ini file or at runtime with error_reporting()
This error is pretty general, but basically what is happening is what it says. You're including mycart.php in a page and on like 117 it starts outputting HTML (or something client-side), once this starts happening you can't modify any of the header information (ex. a redirect). Like jason said though, the reason the error isn't showing up is the error_reporting setting.
EDIT: You can solve some of these problems by using ob_start() and then ob_end_flush() after you've done your header modifying.
Your other server configuration might have output buffering turned on in the php.ini file.
The server has this in php.ini
error_reporting(E_ALL);
if you just want errors then use
error_reporting(E_ERROR | E_PARSE);

Categories