Jump to content

Problems with php header() function


tmyonline

Recommended Posts

Guys:  I'm having a problem with php header() function.  It complains that

 

Warning: Cannot modify header information - headers already sent by (output started at localhost\index.php:28) in localhost\index.php on line 85.  How should I resolve to make it work ?  Thanks.

 

Link to comment
https://forums.phpfreaks.com/topic/91603-problems-with-php-header-function/
Share on other sites

Yeah, I know that the header() function requires that nothing be allowed to output to the browser before it.  However, if I move my header() function to the top of my code, things don't make sense because the criteria that result in using the header() function are not known yet.  For example, I need to use the header() function to re-direct the page (actually to reload itself) if users enter invalid values at the form.  But, I don't know ahead of time whether they will enter invalid values.  If I put the header() at the top of my code, I will not be able to check or detect this kind of thing.  However, if I put it in the bottom, then it complains,...

You still need to show us some code, maybe from the start of the document to the point where the header() is executed (in its original position).

 

Without anything else to go on, try looking for: a single space or newline before your <?php opening tag. Otherwise, is this file being included/required by another php script when its being run?

 

If so, the including script might be printing output before your header script is run. Or maybe it might have the elusive whitespace before the <?php opening tag?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.