This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
“Warning: Headers already sent” in PHP
I tried using xampp lite portable in my flash drive so that I could bring the server anywhere.
But I always get an error when using xampp. This error in particular:
Warning: Cannot modify header information - headers already sent by (output started at /path/to/geeklog/public_html/blabla.php:581) in /path/to/geeklog/public_html/system/lib-blablab.php on line 180
I don't know why I'm getting this error. But when I use wampserver. There's really no problem. And I don't get any errors. What do I need to do to solve this when I'm using xampp.
Is there a portable version of wamp
To ensure your error reporting level is the same across environments, you can set it in your application using error_reporting() and ini_set('display_errors', 1)
Also check your .php files for any whitespace before the opening tag and after the closing tag.
In addition to the points mentioned above, ensure you are not outputting anything before the headers are set, for example the following code would produce an error similar to the one you are receiving:
echo 'Hello, World';
header('Location: http://www.somesite.com');
Is it possible there's a little bitty bit of whitespace outside of the PHP tags in blabla.php line 581? I bet there is.
See, if you have anything outside of PHP tags, that is sent to the browser. And once something has been sent to the browser, you can't send headers (like the sessionID cookies!) anymore.
The problem is likely not XAMPP, but your PHP code as you put it on the flash drive.
The difference you're seeing between environments is most almost certainly a difference in the configuration.
One of two things is happening on the server that isn't emiting Warnings:
1) Output buffering is on by default
2) error_reporting and/or display_errors is set so you're just not seeing the warnings. But if this were the case, your headers still wouldn't get set, so it's probably #1
You can check these settings by looking at the output from phpinfo()
Output buffering, when enabled, buffers any output (regular content not inside tags, anything you echo or print(), etc) on the server and then sends it to the client in one shot.
I'd poke around in your portable version, find php.ini, and try turning output buffering on. Alternatively, you can turn output buffering on at runtime by sticking ob_start() near the top of your script.
The error states: output started at /path/to/geeklog/public_html/blabla.php:581, so I would start there. You need to send all headers before outputting anything, this includes whitespace as mentioned by others here.
Related
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
In the php manual (http://php.net/manual/en/function.header.php) I find the following about http headers:
QUOTE
Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP. It is a very common error to read code with include, or require, functions, or another file access function, and have spaces or empty lines that are output before header() is called. The same problem exists when using a single PHP/HTML file.
<html>
<?php
/* This will give an error. Note the output
* above, which is before the header() call */
header('Location: http://www.example.com/');
exit;
?>
ENDQUOTE
I tried this now (making a study of the HTTP protocol) and find that this doesn't seem to be an issue anymore; I wonder what has changed: has the way php deals with parsing webpages changed? I tried several browsers (Chrome, IE10, IE7) and OS (Windows 8.1, XP) and none of them seem to have an issue with this anymore (see informaticaschool.net76.net/httpdemo3.php for a page that includes exactly the above code example, not giving an error.
For the details of the php version running on that server (I also tried a different apache server) see informaticaschool.net76.net/phpinfo.php.
I admit its a bit of a strange thing to ask why an error does NOT occur but as pointed out i'm studying the workings of http. Looking into a Wireshark trace now to find out what happens exactly in this case, that I knew to be an issue before, I am now surprised to find that NO error appears (and not finding an explanation for it in the php manual).
That server has output_buffering turned on, so all output is buffered and held, which allows you to send headers to the web server even after you have already produced output. See the canonical answer about this issue, section "But it worked on the other server!?".
You must send headers before send output buffer.
Or you can use functions ob_start and ob_end_flush to save output buffer.
I am student (not long being doing PHP so don't know a lot about PHP) but I am trying to get my code to work, at first it was working fine, until it was transfer to a different server but since it had I was getting the following error:
'Warning: Cannot modify header information - headers already sent by (output started at /home/deanj/public_html/login.php:21) in /home/deanj/public_html/login.php on line 60'.
Then I got suggested to use ob_start(); so I tried to use it but didnt get much good results. So what do I need to do use this? and is it the best option? if not what is?
p.s. please make it as simple as you can.
In php.ini set output buffering to On. You should NOT have to modify your code using ob_start() since it is clearly an environment issue. The key to knowing that is in your question, "it was working fine, until it was transfer to a different server".
To fix it, in your php.ini file you want:
output_buffering = On
http://php.net/manual/en/outcontrol.configuration.php
That is also likely why the same code worked on one server, but not on your new one (since output buffering was configured differently).
I wrote a PHP program,
I use session_start() and header() functions, I know I should use this functions before I sending anything to client. it's ok, but for test I send a test message to client with echo "test"; before using header(), but I didn't get any error and header function work without any problem !
In previous versions of PHP at this time I will got a message like :
Warning: Cannot modify header information - headers already sent by (output started at /some/file.php:22) in /some/file.php on line 60
I wan't to know why I didn't get any error message ?!
My php version is 5.3.1 and error_reporting is on E_ALL
You don't see the error because
a. output buffering is on
b. the server ignores your error_reporting function because something else instructs it otherwise
run phpinfo(); and see what it says there about output buffering and about error_reporting.
This might be possible because you write into an output buffer (ob_start) which doesn't actually return anything to the client until you explicitly flush the buffer (ob_flush or ob_end_*) or the script ends.
The fact that you can't send headers after you begun writing the body part of your HTTP response is not a php but a HTTP protocol limitation, so this cannot be version specific either.
Many frameworks like the Zend Framework use output buffers so a developer doesn't need to care about the order.
I found the problem,
I don't use any FrameWork.
the problem was error_reporting('E_ALL');
I wrote this code on first of my program, and so PHP didn't return any errors !
I deleted this line and I get the errors !
This is kidding because this line said to PHP to show ALL errors !
I don't know why PHP don't show any errors.
Im encountered the above error and strucked up, thinking that for 3 hours. Is there any way to solve this??
You are probably trying to start session after the output has begun. Starting a session involves setting HTTP headers. Header can be modified only before sending any output from PHP script. Some PHP installations have output buffering enabled, so it is actually possible to start outputting content before dealing with sessions - PHP engine will sort it out automatically. Apparently, on your system it's disabled by default. Try setting output buffering parameters in php.ini or .htaccess file. If that doesn't help, review your code and check if there is any HTML, echo/print statements before you call session_start(). Also, check for blank characters (new-line character, tab, space) before and after <?php ?> tags. They all must go. Finally, check your editor settings and make sure that Unicode preambe is turned off.