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.
PHPWindows Server 2012Web Development
Last Comment
dgewin
8/22/2022 - Mon
Julian Hansen
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.
Into a file pinfo.php - upload it and call it from your browser. Check the output buffering setting and report back.
Dave Baldwin
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.
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. http://php.net/manual/en/outcontrol.configuration.php#112938
gr8gonzo
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 Savonet
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)
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 Savonet
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
It might be on the other servers output buffering is turned on and not on the new server.
Put
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.