Solved

php header

Posted on 2014-12-17
10
60 Views
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.

Thanks
header.php
use-js.htm
0
Comment
Question by:Richard Korts
  • 5
  • 4
10 Comments
 
LVL 58

Accepted Solution

by:
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

error_reporting(E_ALL);
0
 

Author Comment

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

Expert Comment

by:Gary
ID: 40505277
Could be a space or anything.
When you view source what do you see, the error reporting will give the answer.
0
 

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.

Richard
0
 
LVL 58

Expert Comment

by:Gary
ID: 40505911
Did you add the error reporting?
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 

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!
wo-updt-tst.php
error-reporting.txt
0
 
LVL 58

Expert Comment

by:Gary
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
0
 
LVL 108

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!
0
 

Author Comment

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

Expert Comment

by:Gary
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
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.

744 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now