Extracted the header to a php function in a php libs file and cleaned up some of the php elsewhere.