I was cleaning up the code of a small php application that I wrote long time back. The application was working fine on an old hosting account where it was sitting untouched for almost two years. I was running this application on my local LAMPP installation when I encountered this error:
"Warning: Cannot modify header information - headers already sent by (output started at /opt/lampp/htdocs/sec-app/index.php:35) in /opt/lampp/htdocs/sec-app/index.php on line 86"
Now I was a bit surprised (I don't have much experience in PHP) since this was running fine in that old server and both this and my lampp instance were in PHP5/Apache 2. After searching for sometime I found out that this was due to multiple calls to the php header() function even after the script started outputting html. The remedy was to enable PHP output buffering which I did in the php.ini file. Before going into the configuration, something about output buffering:
Normally, session, cookie or HTTP header data in a PHP script must be sent before any output is generated by the script. If this is not possible in your application, you can enable what PHP calls output buffering, with the output_buffering variable. With output buffering on, PHP stores the output of your script in a special memory buffer and sends it only when explicitly told to do so. This allows you to send special HTTP headers and cookie data even in the middle or at the end of your script;but thsi can have an adverse effect in performance.
output_buffering = Off
You can also pass the output_buffering variable a number indicating the size of the buffer, like:
output_buffering = 1024
I set the value in my php.in as:
output_buffering =4096
That is the default value advised in php.ini. If you want to set this on your production server, you should think about the performance issues. If you don't have access to php.ini on your web server, you can set the same in your .htaccess file as
php_flag output_buffering on
OR
php_value output_buffering 4096
You can add the same setting under a "Directory" directive in apache's httpd.conf file. If even this is not possible or you are not sure about the environment were the script will run, you can enable output buffering in your script itself. Immediately after your php tag opens add the line ob_start(); and immediately before the closing php tag add ob_end_flush(); - or you can enclose the code that causes the error alone within this function duo.
A complete reference of the php.ini variables can be found at: http://www.php.net/manual/en/ini.php
mắt lập tức mất đi đấu trí.
ReplyDeleteVẻ mặt Liễu Tam vô cùng đau khổ, đang muốn nói gì đó thì đột nhiên thấy
hỏa cầu lại vô thanh vô tức xuất hiện, nó lơ lửng ở giữa không trung
không hề nhúc nhích.
Ánh mắt Vương Lâm chợt lóe lên, hứng thú của hắn đột nhiên nổi lên, xem
uy lực của hỏa cầu này người làm thuật tuyệt đối không vượt qua tầng thứ
dịch vụ kế toán thuế trọn gói trung tâm kế toán tại tphcm ngoduong học kế toán tại cầu giấy kế toán cho giám đốc chung cư newskyline văn quán chung cư goldmark city học kế toán phần mềm misa meomeo007 01embesexy trung tâm kế toán tại hà đông chung cư hà nội trung tâm kế toán tại thanh xuân dịch vụ kế toán thuế dịch vụ báo cáo tài chính
mười ba Ngưng Khí kỳ. Hắn sờ sờ cằm, thần thức đảo qua một lần, nhất
thời đã nhận ra người làm phép đang ở trên một cây đại thụ ở cách đó
không xa.
- Ý?
Vương Lâm ngẩn người ra, người làm phép này ước chừng hai mươi
tuổi, tu vi đã đạt tới Ngưng Khí kỳ tầng thứ hai đỉnh phong, tùy thời có
thể tiến vào tầng thứ ba. Thanh niên này có sắc mặt âm trầm, trên mặt
có vết sẹo dài, thoạt nhìn trông rất dữ tợn, nhưng Vương Lâm càng nhìn