[thelist] Tip: whitespace in included PHP causes header() calls to fail

Ian Anderson ian at zstudio.co.uk
Tue Aug 16 05:26:22 CDT 2005

Have just had a horrible morning tracking this down, so I thought I'd 
share it in case others hit the same thing.

<tip type="php" author="Ian Anderson">
In PHP, calls to header( "Location: whatever.php" ) were failing 
silently whenever an include file was used to validate the user's 
session data.

I thought it was something I was doing with cookies or session_start() 
in my included file, but no...

Turned out there was a space *after* the closing "?> " in the included 
file, which was getting written to the browser as unintentional output 
at the start of the HTML. Of course, calls affecting HTTP header will 
not work if output has already been written to the browser.

Hope this helps someone



More information about the thelist mailing list