Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Troubleshooting
Research
Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

php header

Avatar of Richard Korts
Richard KortsFlag for United States of America asked on
PHP
10 Comments1 Solution87 ViewsLast Modified:
I have a strange problem that has now occurred in 2 separate cases.

I have php programs that usually perform some database update. At the end, I normally use the php header function, one example is in the attached header.php.

Note the commented out echo statement just before the headers.

I made some changes to the "real" program, ran it through a php syntax checker to insure no syntax errors, then ran it as a test. The headers are NOT executed, it stays on the page, which is blank so that it purposely produces nothing in the browser. Recognizing I must have some error, I insert some echos into the program to determine where the issue occurs, including the commented out one at the end, just before the headers.

I carefully comment out the headers themselves since I know the echos will negate the headers.

I run it with the echos, it shows them all, including the very last one.

Since I cannot determine the issue, I decide to try another technique I use to see what happens. I use the attached file use-js.htm, which I use by removing the header lines in the php & the exit & inserting the html / javascript after the closing ?> tag.

When I do this, it works perfectly.

I have now had to do this in two different programs in a specific project.

Is there a situation where header does not work based on other conditions?

Again, I am aware it will NOT work if any content is sent to the browser before the headers.

Thanks
header.php
use-js.htm