[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now


php header

Posted on 2014-12-17
Medium Priority
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 2000 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.
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.


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 111

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

650 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