in reply to How to include php-code in header

Why do you have to use PHP?

I see nothing in what you posted that can't be done with Perl and CGI. Is there some local condition that makes that unacceptable?