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

Paul Bennett Paul.Bennett at wcc.govt.nz
Thu Aug 18 19:00:16 CDT 2005

<tip type="php development">
Error Reporting is your friend.

Turning error reporting right up on test servers or during development will literally save you hours of time. Lower levels of error reporting won't report undeclared variables, call's to Header() when there's white space already outputted to the browser and a hundred other errors which can stop things working properly. 

If you don't have access to php.ini (i.e.: on a shared server) you can turn error reporting up at runtime via:

ini_set('error_reporting', E_ALL); 


-----Original Message-----
From: thelist-bounces at lists.evolt.org [mailto:thelist-bounces at lists.evolt.org] On Behalf Of Ian Anderson
Sent: Tuesday, August 16, 2005 10:26 PM
To: thelist at lists.evolt.org
Subject: [thelist] Tip: whitespace in included PHP causes header() calls tofail

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




* * Please support the community that supports you.  * * http://evolt.org/help_support_evolt/

For unsubscribe and other options, including the Tip Harvester and archives of thelist go to: http://lists.evolt.org Workers of the Web, evolt ! 

More information about the thelist mailing list