$node->type throwing PHP errors, occasionally
If your site is barfing on

$type = $node-&gt;type;


then it more than likely means that $node isn't a real node.  If you are using this in page.tpl.php, then I would guess it is because the code is being called on a non-node page.

BTW, you shouldn't need to place any code in template files.  That is what the preprocess functions are for.  If you need to do things with the page template, then check out template_preprocess_page.