Não testei, mas não deves ter grandes problemas.
Certifica-te que o 1º trecho de código é colocado antes de o que alguma coisa seja impressa no browser:
<?php
$show_ad = ($_COOKIE['show_ad'] > strtotime("now")) ? false : true;
if($show_ad) setcookie('show_ad', strtotime('+5 hours'), strtotime('+5 hours'));
?>
<?php if($show_ad): ?>
<div id="popjan">
<a style="float:right; margin-bottom: 22px; margin-right: -22px; z-index: 5px;" href="#" onclick="document.getElementById('popjan').style.display='none';"> <img src="x.png" width="22" height="22" /></a>
<div style="float:center; width:980px; margin-bottom: 10px;"><a href="http://ad.pt" target="_blank" onclick="document.getElementById('popjan').style.display='none';"><img src="a7.png" width="980px;" height="100px" /></a></div>
<div style="clear:both"></div>
</div>
<?php endif; ?>