Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   PHP (http://www.programmingforums.org/forum29.html)
-   -   Warning: Cannot modify header information - headers already sent by (output started at (http://www.programmingforums.org/showthread.php?t=14926)

stu7398 Jan 12th, 2008 8:06 AM

Warning: Cannot modify header information - headers already sent by (output started at
 
I am looking for my contact form when submitting, to redirect to a 'thank you' page, however I receive the following error.
Warning: Cannot modify header information - headers already sent by (output started at

I am new to php programming; clear instructions or language is appreciated.

Thanks.

Sane Jan 12th, 2008 8:37 AM

Re: Warning: Cannot modify header information - headers already sent by (output started at
 
The function, "header", can not be called if you've already made the script output text to the client.

For example:

:

  1. <?php
  2.  
  3. echo 'Hello World!'
  4. header('Content-type: text/plain');
  5.  
  6. ?>


Will throw an error, because it tried to modify the header after all of the headers were sent to the client.

:

  1. <?php
  2.  
  3. header('Content-type: text/plain');
  4. echo 'Hello World!'
  5.  
  6. ?>


This will work. Because the header is modified, and then output is sent.

Jimbo Jan 12th, 2008 11:30 AM

Re: Warning: Cannot modify header information - headers already sent by (output started at
 
Also of note, the PHP code must be the first thing in the file. The following will not work:
:

<!DOCTYPE blah blah blah>
<?php
    header('foo');
?>


Ooble Jan 14th, 2008 12:14 AM

Re: Warning: Cannot modify header information - headers already sent by (output started at
 
If you still want to supress the error, you can do so by calling the error_reporting function. Or, if you want to do it for all files, edit the php.ini file - check the line beginning with "error_reporting = ".

If this is your production server, turning display_errors off and log_errors on in your php.ini file is recommended, so if there are any errors, your users don't see them but you do. If it's your development server, I'd recommend the opposite - set error_reporting to E_ALL, display_errors to On and log_errors to Off.

FERDIKUCUK Feb 18th, 2008 8:06 AM

Re: Warning: Cannot modify header information - headers already sent by (output started at
 
:

<?php
ob_start();session_start();
echo "ferdi kucuk";
header("location : url");
?>


ob_start();

;)


All times are GMT -5. The time now is 9:50 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC