header function in PHP

Hi everyone,

I am moving a webpage I have developed from one webserver to another (due to server upgrades).

On the new server the header commands don't work unless they are literally the only thing on the page.

On the old server AND the test server they work find. I am wondering if there is something I am missing in the PHP setup? any help would be appreciated!

Test server and production have the same version of PHP

I have checked all the things people suggest.. there is no echo's, no whitespace (even in the includes), the only one I could get to work had only the header between the 2 php tags.
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

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.

Julian HansenCommented:
Are all your header directives happening before you output any content?

It might be on the other servers output buffering is turned on and not on the new server.


Open in new window

Into a file pinfo.php - upload it and call it from your browser. Check the output buffering setting and report back.
Dave BaldwinFixer of ProblemsCommented:
You aren't giving us any code or a link to work with.  I must admit that I have never seen that happen even when moving from PHP 4.4 to PHP 5.3 or PHP 5.4 on different servers.
Mukesh YadavFull Stack DeveloperCommented:
Can you share exact code of that page?
Has Powershell sent you back into the Stone Age?

If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone.  For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why.

Ray PaseurCommented:
Check the settings for output buffering.  If it was on in the old server and off in the new server (the default installation setting is off) then you might try turning buffering on.
1. Use Fiddler to examine the raw response of the page and make sure the headers aren't coming but are just ignored or overridden.

2. We need to see your code.

3. If you're doing header redirects, make sure you have a die() or exit() call after the header lines.
Bernard S.CTOCommented:
Usual cause of this problem is that you output some html before running the header function, html being started with any character. Running php without any echo (or error message!) generates no character, and so does not start html.

Obviously you have checked that none of the usual causes is involved.

So (assuming there is no difference in output buffering), this leaves only unusual causes.
Some stupid details I have several times stumbled upon:
- never use ?> at the end of any php included file which has no html output (this would generate at least one character and so would start the html generation); this is the recommended Zend option, so most probably you are already complying with this... which just lets one final "option":
- check that none of your files has a "BOM" in utf-8 or UTF-16. This is really the killing detail,since all looks fine... but the server in some cases consider the BOM as a character, so starts generating html, etc. Not sure how you can check these BOM details. My UEstudio / UEdit shows it to me, presumably the tools you use will provide you with these details. (Not sure but I think that the standard windows notepad can also help)
Ray PaseurCommented:
dgewinAuthor Commented:

Thank you everyone for your responses, through my testing I found that the issue was not in fact the header, it was the following line of code


For whatever reason its not working on the new server, once removed it seems to work normally again.

I find it quite odd because I had been using it for quite some time on different servers and websites for different things in the past with no issues.
Ray PaseurCommented:
Yes, that function comes with a large red warning box in the online man pages.

There really are not enough ways to warn people about the changes in PHP, but we tried here:
Bernard S.CTOCommented:
Altough the problem arises with session_register() rather than header(), it Is still the same problem: some character is sent/echoed before the function is used.

Having session_start as one of the first instructions in my php files has been my practice since a long time...

You have session_start(), right?
Bernard S.CTOCommented:
Some of my painful debugging sessions (let's call that "experience") lead me to the following practice with sessions:
1 - Always place session_start just after <?php of the main program
2 - It's OK to do $_SESSION['xxx']=yyy; but DO NOT EXPECT that later in your program if you want to use the value from $_SESSION['xxx'] it will return the correct/expected value UNLESS...
3 - As soon as you have finished assigning all your values $_SESSION['xxx']= ... or if you are just reading (not writing) the values, do a session_write_close(): this will write changes if any (thus solving the poblem in 2/ above), and also unlock some data. BUT BEWARE it seems that this creates funny things when used with ajax
dgewinAuthor Commented:
Thanks for your comments.

Once I removed the session_register() it fixed all of my issues, I don't have any header() issues now, it was the underlying cause of the problem.

My sessions are working fine without the register.

I will keep all that in mind for the future

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
dgewinAuthor Commented:
I found the solution while testing my code
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

From novice to tech pro — start learning today.