php header

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
Richard KortsAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

GaryCommented:
Are you absolutely sure there is no content being echo'ed?
Pop this at the top of the page and see if you get an error report

error_reporting(E_ALL);
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Richard KortsAuthor Commented:
Gary,

Since I get a totally blank page, how can there be any content?

I'll do the error, be a bit later as I am just leaving now for a few hours.
0
GaryCommented:
Could be a space or anything.
When you view source what do you see, the error reporting will give the answer.
0
Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

Richard KortsAuthor Commented:
View source shows nothing. A blank page.

I have to reconstruct the program; the system is in Beta testing, I have to time it correctly.

Probably tomorrow.

But I think it's 11:15 PM your time now.

Richard
0
GaryCommented:
Did you add the error reporting?
0
Richard KortsAuthor Commented:
Well, well, well.

See attached.

The messages referring to line 367 are, in fact, legit messages. $w is not defined (an error on my part).

But why is it that when I view source BEFORE I put in the error_reporting there is no message about the headers already sent?

My guess is that the host (GoDaddy) has those turned off unless you (I) somehow turn them on.

I will fix the error & try again (without error reporting), my guess is it will work!
wo-updt-tst.php
error-reporting.txt
0
GaryCommented:
In general on a live server error messages are turned off (for security), you have to explicity say show errors to see them
0
Ray PaseurCommented:
Still on GoDaddy?  Some people never learn, and by that I mean that GoDaddy never learns to stop abusing its customers.  Get another hosting company.

Regarding this: "Is there a situation where header does not work based on other conditions?"  Yes, there are several.  Make a Google search for HTTP protocols and HTTP headers, and take in the important details.  The most common is, of course, spurious browser output.

Regarding this: "I will fix the error & try again (without error reporting), my guess is it will work!"  Don't do that, or at least if you do, don't advertise it in public -- you may want to apply for a job some day and a public record of doing something like this would be a black mark on your job application.  Instead, raise the error reporting level to the highest possible and just fix the errors.  Lowering error reporting to suppress error messages is like putting black electrical tape over the "low oil" warning light on your dashboard.  We all know that adding oil will fix the problem.  We also know that hiding the warning light will not fix the problem.  Go with the right thing!
0
Richard KortsAuthor Commented:
Ray,

Most of the error messages are NOT errors.

I have no choice but to use GoDaddy. The customer, convinced by a marketing consultant he uses that GoDaddy is great, picked them & wants to stay.

I will not be applying for a job, ever again. I am past retirement age & still doing my own business because I need the money.

Not all of us have the choice of living in the ideal world.
0
GaryCommented:
There is nothing "wrong" per se with GoDaddy - the millions of customers are testament to that, it's just all the hoops you have to go thru like routing email through their relay server
Not that I would recommend them at all for hosting, I do use them for domain registration though which I have never had a problem with but I do run my own DNS
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.