Go Back   vb.org Archive > vBulletin Article Depository > Read An Article > vBulletin 3 Articles
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools
Tip to Cure: Warning: Cannot add header information - headers already sent by Error
Logician's Avatar
Logician
Join Date: Nov 2001
Posts: 4,449

MCSE, MCDBA, Coder

inside vb code
Show Printable Version Email this Page Subscription
Logician Logician is offline 12-29-2002, 10:00 PM

This is one of the most frequent errors you can get especially when you are hacking vb. It's easy to fix for someone who knows what he is doing, can be very hard to trace for others. If you are getting this error, I can not fix it for you, but some tips as to why this error happens can give you the ground to fix it yourself.

Why the Error happens?
First here is a technical background: Before the server sends a HTML info to the user, it first performs some special actions and sends a "header" page before it starts posting HTML elements of this page. These special actions and header information can not be send AFTER you started to send the HTML elements to user's browser.

For example, one of the most commonly used of these special actions is setting a cookie in user's computer. Cookie setting should be done inside the "header" and header should be sent before anything else is sent. So you can not set a cookie in user's computer say in the middle of a HTML page. If you try, you'll get this infamous error message: "Warning: Cannot add header information - headers already sent by.."

So the reason this error happens is your script started sending some HTML output and after that it tried to send an "header" which is wrong.

The error in vbulletin Hacking:
While you hack vb, you can encounter this problem if you wrongly hacked some vb files (eg. functions.php, config.php, global.php) which runs before HTML output begins. If you accidently started the HTML output in these files, you'll end up with this error. This is because after these files run, vbulletin tries to make some "header" related actions like checking user's cookie or attempting to set a cookie for the user and if you started the HTML output accidently beforehand, header can not be formed and this error happens.

This error is easy to fix if you know where you hacked and what causes this error. Just look for the additions you made in the code and try to find which part of it sends an information to user's browser and remove it.

But if you are a newbie this can be hard to trace because unlike what you think, the displayed information that causes this error is not always very easy to see. This information can be anything, even some invisible elements. For example "new line" command or even a "space" character (both of which are invisible to you) causes this error.

For example:
functions.php or config.php file ends with the line:
PHP Code:
?> 
While hacking these files if you accidently pressed entered after > or put a space character there, you'll get this error because these invisible characters will start HTML output even if you didn't intend to. Same applies if you do the same in the same files right before
PHP Code:
<?php
at the begining.

How to read the the error message you get:
When you receive this error, you'll get a message like this:
Quote:
Warning: Cannot add header information - headers already sent by (output started at D:\webserver\testforum\admin\functions.php:2) in D:\webserver\testforum\admin\functions.php on line 1692
While tracing the error, people tend to check around the line 1692 in functions.php and get confused as they didn't even touch that part while they were hacking the vbulletin. Well, you are on the wrong track: This section is not where error resides, it's just where error is revealed. The error is actually in line 2 of functions.php as the error message gives you the tip: "output started at D:\webserver\testforum\admin\functions.php:2". This is where your HTML output started even though it shouldn't. So you should check around the line where error message says the output started at.

How the fix it:
Needless to say, you have to remove unnecessary line/section that starts the unauthorized HTML output. You have to be careful as this can be an invisible character like a space or new line as mentioned above.

If the output line that produces the error is very small like 1, 2 or 3, you make sure there is nothing else before <?php at the begining of the file. If the line number is too big then make sure you check there is nothing after ?> at the end of file. If the line is in the middle look for a "echo" command there, it may be the cause. These are just frequent occurences of this eror but do not cover all issues regarding this error, so you have to remember the general rule to fix it in your script: Remove any char. that starts the HTML output in the part error mentions.

If you are not very skilled at PHP, have no tools (sophisticated text/HTML editing tools like editplus) that show you invisible chars or can't find the error no matter what then your best bet is to remove the last hack you installed and reinstall it if necessary but this time more carefully. If you are desperate you can replace the file that produces the error with an unhacked vb file which will help you get rid of the error instantly. (Be warned, you'll lose all hacks you applied to this file).

Good luck! :glasses:
Reply With Quote
  #2  
Old 12-30-2002, 09:55 AM
Xenon's Avatar
Xenon Xenon is offline
 
Join Date: Oct 2001
Location: Bavaria
Posts: 12,878
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Good text pal

but i think Hacking Hints and Tips would be the better place for it *move*
Reply With Quote
  #3  
Old 12-31-2002, 07:02 PM
subduck's Avatar
subduck subduck is offline
 
Join Date: Sep 2002
Location: Santa Monica
Posts: 190
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Nice Stuff!
Reply With Quote
  #4  
Old 12-31-2002, 07:56 PM
NTLDR's Avatar
NTLDR NTLDR is offline
Coder
 
Join Date: Apr 2002
Location: Bristol, UK
Posts: 3,644
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

This also happens if you try to echo out from within the files before the headers are sent
Reply With Quote
  #5  
Old 02-12-2003, 05:17 AM
kmfdm_kid2000's Avatar
kmfdm_kid2000 kmfdm_kid2000 is offline
 
Join Date: Mar 2002
Location: Where Towers Crumble (NYC)
Posts: 89
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks, this kind of info is very much appreciated and valued
Reply With Quote
  #6  
Old 02-12-2003, 09:01 AM
Erwin's Avatar
Erwin Erwin is offline
 
Join Date: Jan 2002
Posts: 7,604
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Took me a while to figure this one out on my own.
Reply With Quote
  #7  
Old 03-01-2003, 10:06 PM
Kriek's Avatar
Kriek Kriek is offline
 
Join Date: Jul 2002
Location: Florida
Posts: 135
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Output Buffering

Use output buffering with ob_start() and ob_end_flush(). Although ob_end_flush() isn't needed in MOST cases because it is called automatically at the end of script execution by PHP itself when output buffering is turned on either in the php.ini or by calling ob_start()

PHP Code:
<?php ob_start(); 

// entire script, code, or page here

ob_end_flush(); ?>
Output buffering (PHP 4.0) was originally designed to solve HTTP header errors. I should also mention that Output buffers are stackable, that is, you may call ob_start() while another ob_start() is active. Just make sure that you call ob_end_flush() the appropriate number of times. If multiple output callback functions are active, output is being filtered sequentially through each of them in nesting order.
Reply With Quote
  #8  
Old 10-15-2003, 12:45 PM
sabret00the's Avatar
sabret00the sabret00the is offline
 
Join Date: Jan 2003
Location: London
Posts: 5,268
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by NTLDR
This also happens if you try to echo out from within the files before the headers are sent
thank you so much, that just fixed my problem, i echoed out the doc type before i called the global
Reply With Quote
  #9  
Old 10-16-2003, 02:58 AM
raxafarian raxafarian is offline
 
Join Date: Apr 2003
Posts: 28
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

gotten the same type of error when doing a quick edit on a php file using Cpanel's file edit.

It added a blank line at the end of the file. Once I found that (took a few minutes), the error went away.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 01:46 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04712 seconds
  • Memory Usage 2,287KB
  • Queries Executed 22 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (3)bbcode_php
  • (2)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)modsystem_article
  • (1)navbar
  • (4)navbar_link
  • (120)option
  • (9)post_thanks_box
  • (9)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (9)post_thanks_postbit_info
  • (8)postbit
  • (9)postbit_onlinestatus
  • (9)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete