php header

Posted on 2014-12-17
Last Modified: 2014-12-18
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.

Question by:Richard Korts
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
LVL 58

Accepted Solution

Gary earned 500 total points
ID: 40505261
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


Author Comment

by:Richard Korts
ID: 40505267

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.
LVL 58

Expert Comment

ID: 40505277
Could be a space or anything.
When you view source what do you see, the error reporting will give the answer.
Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users


Author Comment

by:Richard Korts
ID: 40505905
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.

LVL 58

Expert Comment

ID: 40505911
Did you add the error reporting?

Author Comment

by:Richard Korts
ID: 40506017
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!
LVL 58

Expert Comment

ID: 40506029
In general on a live server error messages are turned off (for security), you have to explicity say show errors to see them
LVL 110

Expert Comment

by:Ray Paseur
ID: 40506044
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!

Author Comment

by:Richard Korts
ID: 40506064

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.
LVL 58

Expert Comment

ID: 40506075
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

Featured Post

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question