Show Header error on localhost - php

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.

Related

Error when use session codeigniter

I have a problem while publishing my site. I have a autentication system using session by codeigniter.
When it's run on localhost, its perfect. But when i publish in the server (hosting godaddy), It display this message
Severity: Warning
Message: session_start(): Cannot send session cookie - headers already
sent by (output started at
/home/cristiandelacruz/public_html/crmappsdc/application/config/config.php:1)
Filename: controllers/Login.php
It means you have something output on browser while redirection.
You can do following things:
1) Check which code is printing HTML. And remove it.
eg. Spaces, echo or print statements.
2) if this does not work, add ob_start (); at the file beginning. It stores output in buffer and redirection occurs.
Check if you have blank space before php opening tag in message mentioned file. Try again to save that file without BOM (Copy content into new file and double check you don't have blank space or any characters before file start and save it encoded in UTF-8 without BOM). Maybe helps.
this is happening because your local environment does not have full error reporting turned on, while your hosting provide does. The problem is most likely always there. The reason to that problem is most likely that you are calling Codeigniter's session class $this->session-> ... , however somewhere in the loading of your application, PHP already encountered this: session_start(). To fix it, you need to debug your program and find out where the session is being initialized because the way its currently set up, it is being initialized twice.
Cause:
This error is caused if the your PHP scripts are printing to the browser prior to sending headers. A common example is printing the html tags prior to starting a session, or setting a cookie. The error tells the line that needs to be altered (in this case, it is on /config.php).
Resolution:
To resolve this error remove the lines from the PHP code that are printing to the browser prior to sending headers.
Another common cause for this error is white space either at the beginning or end of the file. The fix is to remove that whitespace from the file. Read the error message carefully. It says output started at ... followed by a file name and a line number. That is the file (and line) that you need to edit. Ignore the second file name - that is only a file that included the file that has the whitespace. The first file is the one you have to edit, not the second one
Source from WHAT DO I DO WHEN I RECEIVE A PHP HEADER ERROR MESSAGE? GoDaddy Forum
Codeigniter Seesion class
I tried above all solutions. finally, I Changed output_buffering in PHP.ini (GoDaddy Server)
output_buffering = on
In PHP 5.4 version by default output_buffering has no value
I updated the PHP version 5.4 to 5.6 and in 5.6 version by default it has value 4096
Now it's working fine

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?

Turn off php warnings in cPanel

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

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?

Categories