Thursday, June 5, 2008

Cannot Modify header, my solution

I have an error on my code php as shown like this:

Warning: Cannot modify header information - headers already sent by (output started at /home/wima/public_html/baak/ondaf/save_daftar.php:1) in /home/wima/public_html/baak/ondaf/save_daftar.php on line 87

I have tried a lot off thing how tho solve this problem. I see that sometimes header run on my code, sometimes not. So for a long time I try to find where is the wrong.

Finally I get an idea when I read some reference on the net. This is the easy tip to solve the problem. My example is when I write the code into part of the form method.

1. I make form1.php that used to input the data.
2. Make a save.php to save the input data. This file that contain header location to to file closing the process. I used the third file because I find that when I just use two files, when user press a reload/refress, the data from post method will process again. So there was double data. So I write header location for well.php (third file)
When use the header location, for not to find error cannot modify header. Try for this file contain php code only. I remove another data that not in php code. Try just only code for identified variables, connection and insert data, header location code that contain a little of variables that will bring by this header location code.
3. Make a well.php. This page is contain message that the process has done, and other information needed to inform for the user.

That is my process that make my header location run. Before I use that last tips, I write other html codein the second page (save page) are like, css, font, some information, so I found error 'cannot modify header location'.