You need to use advance theme and override header() function and place any php code you want to add. Something below
function header(){
qa_html_theme_base::header();
//here your php code..
}
but make sure in this case your php code will start right after default header code so you need to work out to get the result you want. But method would be the same.