Is there any way to have PHP automatically call a function, before a script outputs any HTTP headers?
I’m looking for something like register-shutdown-function, but to register a function that’s called before the output is already sent, not after. I want my function to send a header, so I need something that’s called earlier.
You could also trap everything with
ob_startand then register a callback function to be used when you send the page withob_end_flush. Check out the PHP manual for OB_START