As most of other users said, you can't add PHP code to the template.
But you can easily add templates in a PHP file. The results will be exactly what you want.
1.- Create 2 templates. One for header and one for footer:
a] For Header (is just as example):
HTML Code:
<template name="php_header" templatetype="template" date="" username="" version="">
<![CDATA[
{vb:stylevar htmldoctype}
<html xmlns="http://www.w3.org/1999/xhtml" dir="{vb:stylevar textdirection}" lang="{vb:stylevar languagecode}" id="vbulletin_html">
<head>
<title>Your Title</title>
{vb:raw headinclude}
<vb:if condition="$vboptions['storecssasfile']">
{vb:cssfile forumhome.css, options.css, vbcms.css, widgets.css, sidebar.css, forumhome-rollup.css, usercp.css, additional.css}
<vb:else />
{vb:cssfile forumhome.css, options.css, vbcms.css, widgets.css, sidebar.css, forumhome-rollup.css, usercp.css, additional.css}
</vb:if>
<script type="text/javascript">
<!--
document.write('<script type="text/javascript" src="' + yuipath + '/animation/animation-min.js?v={vb:raw vboptions.simpleversion}"></script>');
var sidebar_align = 'right';
var content_container_margin = parseInt('{vb:math {vb:stylevar forum_sidebar_width}+{vb:math {vb:stylevar padding}*2}}');
var sidebar_width = parseInt('{vb:stylevar forum_sidebar_width}');
//-->
</script>
<script type="text/javascript" src="{vb:raw vboptions.bburl}/clientscript/vbulletin-sidebar.js?v={vb:raw vboptions.simpleversion}"></script>
</head>
<body>
{vb:raw header}
{vb:raw navbar}
<div class="blockbody">
]]></template>
a] For Footer (is just as example):
HTML Code:
<template name="php_footer" templatetype="template" date="" username="" version="">
<![CDATA[
</div>
{vb:raw footer}
</body>
</html>
]]></template>
2.- In your PHP file (assuming that is a file which loads all vB functions that you need, add (again is an example):
Code:
// Header Block
$templater = vB_Template::create('php_header');
$templater->register_page_templates();
$navbits = construct_navbits(array("torget.php?" . $vbulletin->session->vars['sessionurl'] . ""=> "My Page"));
$navbar = render_navbar_template($navbits);
$templater->register('navbar', $navbar);
$header_block = $templater->render();
echo $header_block;
............Hera you can add any PHP code that you like..............
Code:
// Footer Block
$templater = vB_Template::create(php_footer');
$templater->register_page_templates();
$footer_block = $templater->render();
echo $footer_block;
Simple thing and works 100%. I build a complicated Ajax search form using this trick. And is 100% compatible with vBulletin meaning that you can use vboptions, vbphrase, datamanager etc.
Nick