Avatar of Richard Korts
Richard Korts
Flag for United States of America asked on

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
PHP

Avatar of undefined
Last Comment
Gary

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Gary

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Richard Korts

ASKER
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.
Gary

Could be a space or anything.
When you view source what do you see, the error reporting will give the answer.
Richard Korts

ASKER
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
Your help has saved me hundreds of hours of internet surfing.
fblack61
Gary

Did you add the error reporting?
Richard Korts

ASKER
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
Gary

In general on a live server error messages are turned off (for security), you have to explicity say show errors to see them
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Ray Paseur

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!
Richard Korts

ASKER
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.
Gary

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
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23